» Poradna » Programy

Generator nahodnych cisel v C#

 | 

muye mi nekdo poradit jak jednoduse vygenerovat cislo omezene min a max hodnotou???prolezl jsem MSDN ale tam jsou takovy slozity zverstva... :(

Mohlo by vás také zajímat

Odpovědi na otázku

 |   | 

To je základ, dále na http://www.c-sharpcorner.com/Code/2004/Oct/RandomNumbe... Random class defined in the .NET Framework class library provides functionality to generate random numbers.The Random class constructors have two overloaded forms. It takes either no value or it takes a seed value.The Random class has three public methods – Next, NextBytes, and NextDouble. The Next method returns a random number, NextBytes returns an array of bytes filled with random numbers, and NextDouble returns a random number between 0.0 and 1.0. The Next method has three overloaded forms and allows you to set the minimum and maximum range of the random number.The following code returns a random number:int num = random.Next();The following code returns a random number less than 1000.int num = random.Next(1000);The following code returns a random number between min and max:private int RandomNumber(int min, int max){Random random = new Random();return random.Next(min, max);}

Souhlasím  |  Nesouhlasím  |  Odpovědět

Související témata: Generator, MSDN