且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

大于100,000的随机数

更新时间:2023-02-10 12:57:40

// Initialize rand()'s sequence. A typical seed value is the return value of time()
srand(someSeedValue);

//...

long range = 150000; // 100000 + range is the maximum value you allow
long number = 100000 + (rand() * range) / RAND_MAX;

您可能需要使用大于 code>和数字如果(100000 + range)将超过其最大值。

You may need to use something larger than a long int for range and number if (100000 + range) will exceed its max value.