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

Я вызываю функцию здесь (я вызывал ее 5 раз, чтобы проверить, были ли числа случайными):

        if (thePlayer.input == "fight")
        {
            Console.WriteLine("you want to fight");
            thePlayer.autoAttack(enemy1);
            thePlayer.autoAttack(enemy1);
            thePlayer.autoAttack(enemy1);
        }

Однако, когда я проверяю вывод, я получаю точно такое же число для каждых 3-х вызовов функции. Однако, каждый раз, когда я запускаю программу, я получаю другое число (которое повторяется 3 раза), например:

 You attack the enemy for 30 damage.
 The enemy has 70 health left.

 You attack the enemy for 30 damage.
 The enemy has 40 health left.

 You attack the enemy for 30 damage.
 The enemy has 10 health left.

Затем я снова перестрою/отладку/запуск программы, и получу другое число вместо 30, но оно будет повторяться все 3 раза.

Мой вопрос: как я могу удостовериться, что каждый раз, когда я вызываю эту функцию, я получаю другое случайное число? Я просто получаю одно и то же "случайное" число снова и снова.

Вот случайный вызов класса, который я использовал:

    private int randomNumber(int min, int max)
    {
        Random random = new Random();
        return random.Next(min, max);
    }
7
задан Mento 31 August 2011 в 02:13
поделиться