Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void BarcodeButton_Click(object sender, EventArgs e)
        {
            try
            {
                int smallestNumber = 100000;
            int biggestNumber = 5000000;

            //Determine the amount of random numbers
            int amountOfRandomNumbers = 10;

            //Create a list of numbers from which the routine
            //shall choose the result numbers
            var possibleNumbers = new List<int>();
            for (int i = smallestNumber; i <= biggestNumber; i++)
                possibleNumbers.Add(i);

            var result = new List<int>();

            //Initialize a random number generator
            Random rand = new Random();

            //For-loop which picks each round a unique random number
            for (int i = 0; i < amountOfRandomNumbers; i++)
            {
                //Generate random number
                int randomNumber = rand.Next(1, possibleNumbers.Count) - 1;
                barcodeTextEdit.Text = randomNumber.ToString();
                //Remove the chosen result number from possible numbers list
                possibleNumbers.RemoveAt(randomNumber);
            }


What I have tried:

this code true random number or pseudo random generator and why please ?
Posted
Updated 29-Apr-16 0:34am

pseudo random - there's a great explanation here C# in Depth: Random numbers[^]
 
Share this answer
 
Comments
andrew nader 27-May-16 9:29am    
what is seed in this code please ??
Garth J Lancaster 27-May-16 21:42pm    
see OriginalGriff's answer - seed 'could be' anything - it could be (as even I remember doing) a time value, or based on Pi as per OG's answer ... the only way of getting around the limitations of 'seed' as such is to increase the 'entropy' - which is another discussion - see Thomas Pornin's answer here http://stackoverflow.com/questions/3436376/what-is-the-most-secure-seed-for-random-number-generation
andrew nader 31-May-16 7:50am    
class rand in c# use Midsquare method , Linear Congruential Method,Combined Linear Congruential Generators or Random-Number Streams and why
All software based methods are pseudo random: They use a "fixed algorithm" to generate the sequence of "random" numbers and the whole sequence can be repeated by providing the same seed value. The Random class uses the system clock to initialize the sequence when the instance is created, as can easily be seen if two instances are created in quick succession.
 
Share this answer
 
Comments
andrew nader 29-Apr-16 6:53am    
what is fixed algorithm ?
OriginalGriff 29-Apr-16 7:00am    
What do you think it is?
andrew nader 29-Apr-16 7:03am    
how to check random in this code?
OriginalGriff 29-Apr-16 7:07am    
https://en.wikipedia.org/wiki/Randomness_tests
andrew nader 27-May-16 9:50am    
what is seed in this code please??

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900