samedi 29 septembre 2018

C# Random not Random at all

I am creating a LAN panic-button application, where the Server (TCP Server that handles multiple clients) will send a "panic" string to clients and the clients should pick a random website from a List of websites and open it.

So far, I tried my way (example below), opened multiple instances of the client on my PC and fired the panic button on the server.

The problem is that all clients open the same website and not a randomly selected one, so I end up with 10 new tabs on Chrome, navigating to the same website.

Why, although they are different instances, the randomly selected element is the same?

static string randomSite()
{
    Random Ram = new Random(DateTime.Now.Millisecond);
    List<string> sites = new List<string>();
    sites.Add("https://www.google.com");
    sites.Add("https://www.youtube.com");
    sites.Add("http://www.skai.gr");
    return sites[Ram.Next(0, sites.Count)];
}




Aucun commentaire:

Enregistrer un commentaire