How do I create Random Numbers advanced.

Get help using Construct 2

Post » Wed Dec 30, 2015 7:59 pm

Hello Everybody and happy Holidays.

I have a quick question.

I have 6 fields and can get random numbers in them. The Issue I am having is I don't want to have two, three or even four of the same number displayed.

How would I check to see if a number is used and keep it from reusing that number?
B
29
S
13
G
10
Posts: 355
Reputation: 8,317

Post » Wed Dec 30, 2015 8:30 pm

If the chance of rolling the same numbers is low (for example your range is 1-100, and you wanna fill 6 fields), I would probably just do a while loop (roll -> check if number is present; if it is, reroll; end loop when number is not present).

If the number of fields is closer to the range of values you are filling into them, I would do something like:
Image
this would circumvent unnecessary retries, but need a bit more memory, since you build an array (but memory would only be a problem for big ranges)
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Wed Dec 30, 2015 8:44 pm

ImageImageImage
B
71
S
21
G
203
Posts: 3,582
Reputation: 115,008

Post » Thu Dec 31, 2015 3:42 am

Thanks for the replies, I had found a topic on this and used the RandonNos snippet I found. Only issue I am having now is that the array with width 5 on random number does not line up with my balls.

see demo here.
scirra.com/arcade/other-games/lottery-number-picker-4491

worked great for Pick 3 and Pick 4 as each array was per number. But when making PowerBall and Mega Millions the white balls are all in one array.

any Ideas on how to adjust to fix it?
B
29
S
13
G
10
Posts: 355
Reputation: 8,317


Return to How do I....?

Who is online

Users browsing this forum: CrudeWall and 12 guests