C++ random numbers
C++ random numbers
如何在Linux和C++中使用随机数?
我找到了一些我想使用的代码,它有行
srand((unsigned)time(0));//seed
但是gcc说
board.cpp:94:24:错误:未在此作用域中声明"time"
我已经包括以下文件
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <algorithm>
您需要
#include <ctime>
以访问CCD_ 1功能。
您还没有包含定义函数的头,为了让程序知道如何调用time(),您需要添加以下内容:
#include <time.h>
为了挑剔(代码风格),您的调用应该更正确地为时间(NULL),而不是时间(0)
您需要包括<time.h>
事实上,它错过了时间函数try:的include
#include <time.h>
你可以去那里了解更多关于srand:的解释
http://www.cplusplus.com/reference/clibrary/cstdlib/srand/
相关文章:
- <random>在实践中应该实际使用哪个随机数引擎? std::mt19937?
- 如何计算"numbers in for"的数量
- 是否可以为boost::random::uniform_int_distribution<>设置确定性种子?
- 'generate'不是窗口头文件中'std::random_device'的成员<random>
- 数组打印"random"值时出现问题
- 使用""的不可重现的随机数<random>
- <random> 尽管不是常量,但所有发行版都是线程安全的吗?
- 从时间生成'random'数字?
- "How to make a recursive call for palindrom numbers without reverse function in c++?"
- 无法在 c++ 中包含"random"头文件
- Nemiver 找不到文件 /build/glibc-LK5gWL/glibc-2.23/stdlib/random.c
- 如何在 c++ 中正确读取 GRC 块"Random Source"的字节输出数据到自己的 OOT 块中?
- Large digit numbers
- "sum root to leaf numbers"问题的解决方案
- 如何从C++<random>获得一致的行为
- 为什么 random() 在窗口中不起作用
- c++ random numbers srand
- C++ Random numbers 0 - 16
- C++ random numbers
- C++11 random numbers