How do I create Random Numbers advanced.

0 favourites
  • 4 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • 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?

  • 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:

    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)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)