首页 > 解决方案 > 程序映射的伪随机算法

问题描述

我正在创建一个随机制作地图的游戏。问题是更新函数调用非常快,甚至使用:

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;
    }
}

我正在寻找一种伪随机算法,它可以为我提供足够的随机性来更改函数的每次调用。

标签: c++2d-games

解决方案


推荐阅读