# [SOLVED] Make a more complex dice (random number generator)?

Get help using Construct 2

### » Mon Aug 10, 2015 10:27 pm

@lukezero just a thought...
try to avoid "While" loops..... whenever you can..
B
67
S
24
G
7
Posts: 1,519
Reputation: 11,094

### » Mon Aug 10, 2015 11:29 pm

Perhaps he could use a function to avoid "While" loops?
B
28
S
17
G
157
Posts: 893
Reputation: 81,759

### » Tue Aug 11, 2015 12:31 am

"while" can be very useful to use. No reason to avoid it. You just need to make sure you're not causing an infinite loop by using it.

The method I proposed was to choose a random number and if it's either of the last two values it tries again. The only drawback is it could have the chance of looping a lot if one of the last values gets picked over and over again, but that is a slim chance in this case.

The method korbaach suggests is to have a list of all the numbers except the two last and choose one of them. Arrays could be used to do it or even text like the following.

number cur=0
number last1=0
number last2=0
text list=""

on click
--- set last2 to last1
--- set last1 to cur
--- set list to replace(replace("123456", str(last1), ""), str(last2), "")
--- set cur to int(mid(list,int(random(len(list))),1))
B
97
S
36
G
131
Posts: 5,520
Reputation: 83,478

### » Tue Aug 11, 2015 5:19 am

R0J0hound wrote:"while" can be very useful to use. No reason to avoid it.

@R0J0hound Of course, you're right,my fault...perhaps better advice was, be extremely careful when you use "While" loops
B
67
S
24
G
7
Posts: 1,519
Reputation: 11,094

Previous