2.2.16

Random Number Generation

Test yourself

Random Number Generation

It is often useful to generate random numbers in Greenfoot programs.

Illustrative background for Random number generationIllustrative background for Random number generation ?? "content

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.
Illustrative background for Random number generationIllustrative background for Random number generation ?? "content

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.
Illustrative background for Uses of random number generationIllustrative background for Uses of random number generation ?? "content

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.

Jump to other topics

1Computer Systems

1.1Systems Architecture

1.2Memory & Storage

1.3Computer Networks, Connections & Protocols

1.4Network Security

1.5Systems Software

1.6Ethical, Legal, Cultural & Environmental Concern

2Computational Thinking, Algorithms & Programming

2.1Algorithms

2.2Programming Fundamentals

2.3Producing Robust Programs

2.4Boolean Logic

2.5Programming Languages & IDEs

Unlock your full potential with Seneca Premium

  • Unlimited access to 10,000+ open-ended exam questions

  • Mini-mock exams based on your study history

  • Unlock 800+ premium courses & e-books

Get started with Seneca Premium