生成随机数

扫码查看
本文介绍了生成随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,


这是我到目前为止的第二篇文章。感谢第一篇文章给我的所有建议。


现在我遇到生成随机数的问题。我知道如果我们想生成一个随机数,我们可以使用:


int tempNUM = rand();


但是,一旦我执行程序,生成的数字总是相似的,我从互联网上找到了这个。它说需要添加这一行来使数字生成不同:


srand((无符号)时间(0));


当我添加该行时,我的结果就像地狱一样..有人可以请赐教。谢谢你

Greetings,

This is my second post till now. Thanks for all the advice given to me for the first post.

Now I''m having problem with generating random numbers. I know if we want to generate a random number, we can use:

int tempNUM = rand();

But, once I execute the program, the generated number is always similar, and I found this from the internet. It says need to add this line to make the numbers generated differently:

srand((unsigned)time(0));

When I add that line, my result is like hell.. Could someone please kindly enlighten me. Thank you

推荐答案




这篇关于生成随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 17:26
查看更多