Random Number Generation
Computer Science: OCR GCSE, topic 2.2.16
Random Number Generation
It is often useful to generate random numbers in Greenfoot programs.

Random number generation
- Random numbers can be generated using a method of the Greenfoot class:
Greenfoot.getRandomNumber(MIN, MAX);- This line will generate a random number between MIN and MAX.

Random number generation
- There is also an alternative way to use this method:
Greenfoot.getRandomNumber(MAX);- This line will generate a number up to but not including MAX.

Uses of random number generation
- Random number generators are used for many reasons:
- Decisions in games e.g. dice throws and coin flips.
- Simulations of systems with chance.
- Cryptography.
Test yourself on Random Number Generation
The
getRandomNumbermethod has how many ways it can be used?What numbers might be generated by:
Greenfoot.getRandomNumber(10);