c++ - 程序映射的伪随机算法
问题描述
我正在创建一个随机制作地图的游戏。问题是更新函数调用非常快,甚至使用:
srand(time(NULL));
rand()%2;
它每次都生成相同的图块组。有我的代码:
void setTex(){
srand((unsigned)time(NULL));
switch(rand()%2){
case 0:
texture = TextureManager::LoadTexture("assets/ground_1.png");
break;
case 1:
texture = TextureManager::LoadTexture("assets/ground_2.png");
break;
case 2:
texture = TextureManager::LoadTexture("assets/water.png");
break;
}
}
我正在寻找一种伪随机算法,它可以为我提供足够的随机性来更改函数的每次调用。
解决方案
推荐阅读
- android - 当线程没有阻塞时,为什么还要调用 nativeWake()?
- python - 使用var运行sql select的python不起作用
- r - 为什么我们看不到 R 中大型数据框的所有行?当我们尝试查看完整的数据帧时,为什么 R 忽略了大多数行作为 o/p?
- visual-studio-code - vscode.workspace.onDidCloseTextDocument 的回调函数正在开发中,但在打包到 vsix 后没有
- ruby-on-rails - 如何正确设置 Bootstrap 以处理所有 Rails .html.erb 视图文件?
- javascript - 让机器人发送一条看起来像是从另一个用户发送的消息
- javascript - 我想使用 localStorage 来保存用户输入的一些数据,以便我可以在 HTML 中显示信息
- node.js - socket.io 在客户端刷新页面后失败
- python - 在python中合并具有不同长度和列的数据框列表
- jquery - 用星号屏蔽 EditorFor 模型的整数值