How to quickly and easily produce random numbers that will always be different each time.
ETGgames
Member, PRO Posts: 190
Just thought I'd let you guys know considering I can't really find anything on the forums, the next best alternative is using table. I just created an index attribute, call it index1. To get a random value thats always different, you do
change attribute index1 to (index1 + random(1,(max value - 1))%max value
Using simple modulus, this makes it easily achievable. Note how the minimum value of index1 will be 0, as modulus always starts at remainder of 0. You don't want the upper boundary of the random value to be the max value, because if the random function did in fact give the value as the max value you wanted, then you would get the same number, hence index1 would be the same two or more times, which is not what is wanted!!!
Comments
Here´s one way (attatched demo)
Click the white box. It will give you a random number between 0 and 1000. No repeats.
You can easily increase the max value from the change attribute behavior in the loop.
I´m sure there´s better ways of doing this, but this came to my mind first.
Mental Donkey Games
Website - Facebook - Twitter
Thats a lot more complex than my method, mine simply requires one change attribute bubble, not a whole table and weird things going on..
My Games:
https://itunes.apple.com/us/developer/ethan-sarif-kattan/id825823924
https://play.google.com/store/apps/developer?id=ETG+Ltd.
Website: https://etggames.com