• C# Unique Number
    3 replies, posted
Hi, I need to generate a random number that won't change when I restart the program, but is different on every PC.
Will this help? [url]http://www.vcskicks.com/hardware_id.php[/url]
Something like [csharp]System.Random pnrg = new System.Random(System.Environment.MachineName.GetHashCode());[/csharp] Though then the numbers can easily be changed by changing the computers name. Could be enough for your purpose though? [editline]12th December 2010[/editline] :ninja: [editline]12th December 2010[/editline] Actually, when you want it to run on Mono, then you cannot use System.Management.
You could consider using a hash based on the MAC address of the first physical network adapter or even multiple physical adapters. Issues & merits & other shit: - Not guaranteed to be unique, but will most likely be unique. - Only use physical adapters as virtual adapters can be added / removed at run-time. (VM ware host adapters, etc.) - Include disabled adapters, otherwise enabling / disabling an adapter would change the hash. - Will persist even with a hard drive change. - Sort the adapters by MAC address so that the order is always the same.
Sorry, you need to Log In to post a reply to this thread.