Randoms…
In the last post i showed you the basic uses or randoms…
But, how useful are they?
To be honest. Randoms are awesome, they allow any game to alter slightly and so every time, the experience changes. In most classic RPG’s the character could find objects ‘randomly’. And it was this ‘chance’ that kept people playing. So, one advantage already is to not bore the player.
But, if we randomise the game, then it could change the difficulty. And so it would be slightly luck if you got a high score. Most games use randoms however to allow the game to change. Eg, no-one can post internet articles explaining how to complete a game – Keeps them playing and allows the game to ‘evolve’.
For example; it may allow the game to be easy in some parts and difficult in others. That’s why it is important to use the random with limits…
Here is a short function you could use…
1 2 3 4 5 | randomMinMax(min, max){ randomNum = random()*(max-min)+min; randomNumRound = Math.Round(randomNum) return randomNumRound } |
Eg…
1 | trace(randomMinMax(10,20)) |
– Would return a random integer between 10 and 20
