[TIP] Randomize A Set Of Numbers, Rube Goldberg Style
netdzynr
Member Posts: 296
It seems like every other day in the forums, there's a request for randomizing a set of numbers. Here's a brute force (mechanical) technique for generating a non-repeating set of random numbers. This method is based on the grid game template posted several days ago. The concept is to continuously spawn actors at random positions on a grid. Each slot in the grid corresponds to a number. Any actors generated in the same slot on the grid are destroyed (and removed from the overall actor count). This process repeats until the desired number of random numbers (actors) is reached, and each actor remaining on the grid reports its location as a random number.
To use this with your own set of numbers, you need to create a grid with a slot count that represents the range of numbers you need (ie 1 to 25 = 25 slots). You could use one long single-row grid, but the grid used here has multiple rows so the results can be monitored.
Clearly this is not an ideal method, and the behavior is a little squirrely, but for folks who are desperate for a randomizing function, this could be an option.
http://gamesalad.com/game/play/80068
To use this with your own set of numbers, you need to create a grid with a slot count that represents the range of numbers you need (ie 1 to 25 = 25 slots). You could use one long single-row grid, but the grid used here has multiple rows so the results can be monitored.
Clearly this is not an ideal method, and the behavior is a little squirrely, but for folks who are desperate for a randomizing function, this could be an option.
http://gamesalad.com/game/play/80068
Comments
Truly random data can't come from within the system itself. The "seed" has to come from outside the system. Such as a radioactive isotope, the system clock, some network noise, radio noise, the random moment and location that the player presses the start button, the position of the x/y accelerometers, etc.
I have found these to be far simpler:
METHOD #1
// The core concept here is that the accelerometer data is truly random and updating constantly. note: this doesn't actually overwrite game.time. Game.time is read-only, so i am just using it as a dummy variable for data that doesn't need to be saved. This only works on devices, it won't work on the web or computers because the accelerometer always reports 0 on those targets.
constrain attribute game.time = random(-abs(accelerometer.x*100), abs(accelerometer.y*100))
METHOD #2
// This uses particle emitters to generate random data. Then the "seed" is the random moment in time when the player presses the screen. Yes, this could be done with timers too but particle emitters are prettier. Plus it works on the web or computers too!
Scene 1
particle emitter
direction: random(0,360)
velocity: random(10,100)
Rule Mouse Down
Change Scene: Next Scene
Check my method!
it is much simple, the only problem is all the numbers is in order, not really random.
http://gamesalad.com/game/play/80029
http://gamesalad.com/forums/topic.php?id=10673
The bottom line is, even though GameSalad claims to be an environment that requires no programming, they need to add some programming features.