跳转到主要内容

Random Numbers

Random Numbers

This library obtains random numbers.

randomSeed

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.
Syntax
randomSeed(unsigned int seed)
Parameters
seed: A number to generate the seed
Returns
None

random

Description
Obtains the random numbers. Always call the randomSeed function before using this function.
Syntax
long random(long min_num, long max_num)
Parameters
min_num: Lower bound of the random value, inclusive (optional)
max_num: Upper bound of the random value, exclusive (optional)
Returns
A random number (long)

Sample Program

Output random numbers between 0 and 99 in 100ms intervals via serial communications.


#include <Arduino.h>
#define INTERVAL 100
 
void setup()
{
    Serial.begin(9600);
    randomSeed(millis());
}
 
void loop()
{
    Serial.println( random(0, 100) );
    delay(INTERVAL);
}

支持

支持社区

支持社区

在线询问瑞萨电子工程社群的技术人员,快速获得技术支持。
浏览常见问题解答

常见问题

浏览我们的知识库,了解常见问题的解答。
提交工单

提交工单

需要咨询技术性问题或提供非公开信息吗?