Click here to Skip to main content
15,894,405 members
Articles / Programming Languages / C#

How to generate many random various numbers?

Rate me:
Please Sign up or sign in to vote.
4.27/5 (9 votes)
9 Sep 2011CPOL 16K   2  
Use LINQ:public IEnumerable GenerateRandomSequence(int min, int max){ var rnd = new Random(); return Enumerable.Range( min, max-min ).OrderBy( n => rnd.Next() );}You'll need a reference to System.Core to use this, and a version of .NET that supports LINQ.If you're using...

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

Please Sign up or sign in to vote.
6 Sep 2011Luc Pattyn
This is an alternative to "How to Generate Many Random Various Numbers?"
Please Sign up or sign in to vote.
28 Jan 2011Shahin Khorshidnia 3 alternatives  
How to generate many random various numbers?
Please Sign up or sign in to vote.
12 Sep 2011kribo
Found this little peace of code in book and kept it.using System.Security.Cryptography;public static int RandomNumber(int maxvalue){ RandomGenerator random = RandomGenerator.Create(); byte[] r = new byte[1]; random.GetBytes(r); double val = (double)r[0]/byte.MaxValue; ...

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Woodland Furniture
United States United States
Started programming on a Commodore Vic-20 at 6 years old. Never really stopped since then. Fluent in x86 Assembly, C++ (ATL & MFC), C# (ASP.NET/WF/WPF/Silverlight), HTML, & Javascript. Really excited at the fast pace at which new technology is released.

Comments and Discussions