生成一个随机数
random()
函数可用于生成伪随机数:
void setup() {
Serial.begin(9600);
}
void loop() {
long randomNumber = random(500); // Generate a random number between 0 and 499
Serial.println(randomNumber);
randomNumber = random(100, 1000); // Generate a random number between 100 and 999
Serial.println(randomNumber);
delay(100);
}