【Arduino 函数练习】随机数random ()和 randomSeed()
程序员文章站
2022-07-12 10:23:26
...
Arduino 官网:
参考 > 语言 > 功能 >随机数 >随机数
随机数函数:
-
random()
-
randomSeed()
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 30
randNumber = random(40);
Serial.print(randNumber);
Serial.print("-");
// print a random number from 0 to 40
randNumber = random(40);
Serial.print(randNumber);
Serial.print("-");
//print a random number from 0 to 10
randNumber = random(40);
Serial.print(randNumber);
Serial.print("-");
randNumber = random(40);
Serial.print(randNumber);
Serial.println("\n");
delay(200);
}
上一篇: ROS中使用Eigen库
下一篇: Python-Djangon