arduino Random Numbers

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • random(max) //Returns a (long) pseudo-random number between 0 (inclusive) and max (exclusive)

  • random(min, max) //Returns a (long) pseudo-random number between min (inclusive) and max (exclusive)

  • randomSeed(seed) //Initializes de pseudo-random number generator, causing it to start at a specified point in its sequence.

Parameters

ParameterDetails
minThe minimum possible value (inclusive) to be generated by the random() function.
maxThe maximum possible value (exclusive) to be generated by the random() function.
seedThe seed that will be used to shuffle the random() function.

Remarks

If randomSeed() is called with a fixed value (eg. randomSeed(5)), the sequence of random numbers generated by the sketch will repeat each time it is run. In most cases, a random seed is preferred, which can be obtained by reading an unconnected analog pin.



Got any arduino Question?