Arduino - Random

Arduino

Guide

Tutorials

Reference

Hardware

Software

Forum

Playground

Exhibition

Hacking

FAQ

Buy

Language | Libraries | Comparison

## long random(max)
long random(min, max)

#### Description

The random function allows you to return pseudo-random numbers for use in your applications. NOTE: Use this after using the randomSeed() function.

#### Parameters

min - optional starting range (ie: from "50" - 300).

max - the overall range of random numbers you'd like returned.

#### Returns

long - returns the random number.

#### Example

    long randNumber;

    void setup(){
      Serial.begin(19200);
    }

    void loop(){
      randomSeed(analogRead(0));
      // return a random number from 50 - 300
      randNumber = random(50,300);

      // example with only a range, which would return
      // a number between 0 - 300
      // randNumber = random(300);
      Serial.println(r);
    }

#### See also

- randomSeed
- millis

Reference Home Reference Home

Corrections, suggestions, and new documentation should be posted to the Forum.

Edit Page | Page History | Printable View | Recent Site Changes