小编Men*_*nto的帖子

C#随机数不是"随机的"

我知道C#Random类不会产生"真正的随机"数字,但是我想出了这个代码的问题:

    public void autoAttack(enemy theEnemy)
    {
        //Gets the random number
        float damage = randomNumber((int)(strength * 1.5), (int)(strength * 2.5));

        //Reduces the damage by the enemy's armor
        damage *= (100 / (100 + theEnemy.armor));

        //Tells the user how much damage they did
        Console.WriteLine("You attack the enemy for {0} damage", (int)damage);

        //Deals the actual damage
        theEnemy.health -= (int)damage;

        //Tells the user how much health the enemy has left
        Console.WriteLine("The enemy has {0} health left", theEnemy.health);
    }
Run Code Online (Sandbox Code Playgroud)

然后我在这里调用函数(为了检查数字是否随机,我调用了5次):

        if (thePlayer.input == "fight")
        { …
Run Code Online (Sandbox Code Playgroud)

c# random numbers

7
推荐指数
2
解决办法
6140
查看次数

标签 统计

c# ×1

numbers ×1

random ×1