生成一個隨機數

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);
}