Generating Random Numbers on RTL8720DN

Hello.
Is there a way to generate random or at least pseudo-random numbers on RTL8720DN in the Arduino IDE?

Hi @Northstrix ,

Welcome to AmebaIoT Forum and hope you enjoy using RTL8720DN.

In Arduino IDE, there is Arduino built-in library that contains an API random() to generate random numbers.

You may refer to the code below as a reference:

long randNumber;

void setup() {
  Serial.begin(9600);

  // if analog input pin 0 is unconnected, random analog
  // noise will cause the call to randomSeed() to generate
  // different seed numbers each time the sketch runs.
  // randomSeed() will then shuffle the random function.
  randomSeed(analogRead(0));
}

void loop() {
  // print a random number from 0 to 299
  randNumber = random(300);
  Serial.println(randNumber);

  // print a random number from 10 to 19
  randNumber = random(10, 20);
  Serial.println(randNumber);

  delay(50);
}

Thanks!

1 Like

Ok. Thank you so much.

1 Like