+ 1
Program to print random numbers with out any relationship between each numbers or any pattern, numbers from 0 to 99999
To print like this eg. 5,52,84,7,87,874,089,
7 Respuestas
+ 4
Here example of program that print 10 random numbers from 0 to 99999:
https://code.sololearn.com/cluzQZ1yq5fO/#cpp
What is happening in the program:
1) Generating seed of random numbers by using function rand().
2) For using rand() libriary <cstdlib> was included.
3) Code: "rand()%100000" will return you numbers from 0 to 99999, as you see writen number 100000 not included.
4) Every run of the program will give you the same 10 numbers, if you not include code: "srand(time(NULL));". The time() function will return the computer’s time. On transformer, this is expressed in terms of the number of seconds that have elapsed since Jan 1, 1970 (the Epoch). The function time(NULL) will return the number of seconds elapsed in computer time.
5) For using this function you should include <ctime> libriary.
6) Loop for 10 times run function rand() for return you 10 random numbers.
7) Function cout output to the screen every result 10 times.
Good luck!
+ 2
@Tiger Jones
can you explain words: "a very bad randomness"?
+ 2
Because of srand(time(NULL)) there is no repeating output, result is some portion of machine time seconds.
And yes, if I only use only rand() It will be not well distributed.
0
You can't calculate truely random numbers on a computer. But you can take a look in the random header.
0
You know that you shouldn't be using rand, because it has a very bad randomness?
0
The output repeats very fast and isn't well distributed.
0
If you would do it in every loop cycle you wouldn't get this problem (although the numbers wouldn't be random anymore)