VisualStudio中的srand和64bit time_t [英] srand and 64bit time_t in VisualStudio

查看:182
本文介绍了VisualStudio中的srand和64bit time_t的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我是C的初学者(和一般编码),试图在视觉工作室中生成简单的随机数。



但似乎由于我的系统是64位,srand(时间(NULL))不起作用。



经过一些搜索,我也尝试了srand((unsigned int)time(NULL))但是编译器仍然给出了一条错误信息(关于srand返回空值)。



是否还有绕过这个问题?

Hi I'm a beginner of C (and coding in general), trying to generate easy random numbers in visual studio.

However it seems that due to my system being 64bit, srand(time(NULL)) do not work.

After some searching, I tried srand((unsigned int)time(NULL)) too but the compiler still gave an error message (about srand returning void value).

Is there anyway to bypass this problem?

推荐答案

std :: srand 仅将随机数生成器初始化为沿伪随机序列的特定点。它没有返回任何东西。你需要调用 std :: rand 来实际得到一个数字。
std::srand only initialises the random number generator to a specific point along the pseudo-random sequence. It doesn't return anything. You need to call std::rand to actually get a number.


这篇关于VisualStudio中的srand和64bit time_t的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆