[TIP] Randomize A Set Of Numbers, Rube Goldberg Style

netdzynrnetdzynr Member Posts: 296
edited November -1 in Working with GS (Mac)
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

Comments

  • ORBZORBZ Member Posts: 1,304
    Except it doesn't work :P

    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
  • netdzynrnetdzynr Member Posts: 296
    For generating a truly random number, your methods seem reasonable. But I think you're missing the second half of the problem which is to randomize a fixed set of a numbers. The above grid method is goofy, yes, but given the absence of arrays and programmatic reference to variables, I believe it does the job.
  • ORBZORBZ Member Posts: 1,304
    Ohh, I misunderstood what you were trying to do. Yes, to randomize an existing set your method works, quite cleverly actually considering there is no arrays :)
  • victorkin11victorkin11 Member Posts: 251
    Hi netdzynr!
    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
  • netdzynrnetdzynr Member Posts: 296
    Very fast victorkin, and great for 5 numbers. But how about for 20 numbers, 50, or 100? Very few people would want to write the rules for this.

    The bottom line is, even though GameSalad claims to be an environment that requires no programming, they need to add some programming features.
  • JackBQuickJackBQuick Member Posts: 524
    I like your solution, netdzynr -- especially the visuals :) Yours, too, victorkin11. Love the way you both thought outside the box.
Sign In or Register to comment.