RUI3 (RAK Unified Interface 3) - RAK4631
RandomNumber

Functions

long random (long min, long max)
 
void randomSeed (unsigned long seed)
 

Detailed Description

Function Documentation

◆ random()

long random ( long  min,
long  max 
)
Description
The random function generates pseudo-random numbers
Syntax
random(max);
rnadom(min, max);
Parameters
min(optional)lower bound of the random value, inclusive(default = 0)
maxupper bound of the random value, exclusive
Returns
A random number between min and max-1(Type: long)
Example
void setup() {
  Serial.begin(115200);//UART0 baudrate 115200
  randomSeed(analogRead(0));
}

void loop() {
  Serial.print("Random number(0 ~ 999) : ");
  uint32_t l = random(1000);
  Serial.println(l);    

  //delay 1 second
  delay(1000);
}

◆ randomSeed()

void randomSeed ( unsigned long  seed)
Description
randomSeed() initializes the pseudo-random number generator, causing it to start at an arbitrary point in its random sequence. This sequence, while very long, and random, is always the same.
If it is important for a sequence of values generated by random() to differ, on subsequent executions of a sketch, use randomSeed() to initialize the random number generator with a fairly random input, such as analogRead() on an unconnected pin
Syntax
randomSeed(seed);
Parameters
seednumber to initialize the pseudo-random sequence
Returns
void
Example
void setup() {
  Serial.begin(115200);//UART0 baudrate 115200
  randomSeed(analogRead(0));
}

void loop() {
  Serial.print("Random number(0 ~ 999) : ");
  uint32_t l = random(1000);
  Serial.println(l);

  //delay 1 second
  delay(1000);
}