大于100,000的随机数 [英] Random number bigger than 100,000
本文介绍了大于100,000的随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用C / C ++编写,我想创建大于100,000的随机数。我怎么会这样做? rand();
I'm writing in C/C++ and I want to create a lot of random numbers which are bigger than 100,000. How I would do that? With rand();
推荐答案
// 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.
这篇关于大于100,000的随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文