The question was as follow:
Write a function in C which returns a random integer between 1 and 20. One
extremely important caracteristic of the function is that it must return a different
integer each time it is called. This, obviously, implies that it can only be
called twenty times.
Use this signature:
int generate_unique_random()
{
/* to be completed */
}
The most important part(in my opinion,of course) in it was to ensure that each time a
unique number be returned when the function is to be called.Check out my code below:
#include
#include
#include
One important thing that should be noted here is the fact that randomness is something very unnatural to do.Nothing is random in the computer,the only thing that is random is nature.However to generate random number in the above case,the use of the function rand() is made.I'm trying to enhance my code without making use of the rand() funtion but still using the same algoritmn...will post it as soon as possible.
No comments:
Post a Comment