jeudi 2 mai 2019

Weird Random behavior [duplicate]

This question already has an answer here:

Consider the following:

SomeObject o1 = new SomeObject("obj 1");
SomeObject o2 = new SomeObject("obj 2");

for (int i = 0; i < 10; i++)
{
     o1.Method();
     o2.Method();
}

Where:

public class SomeObject
{
    string name;
    public SomeObject(string name)
    {
        this.name = name;
    }
    public void Method()
    {
        Console.WriteLine($"{name}:  {new Random().Next(1, 101)}");
    }
}

Output:

obj 1: 99

obj 2: 99

obj 1: 99

obj 2: 99

obj 1: 99

obj 2: 99

obj 1: 99

obj 2: 99

obj 1: 99

obj 2: 99

That's doesn't looks like random numbers




Aucun commentaire:

Enregistrer un commentaire