[algogeeks] Re: random function

2011-09-20 Thread saurabh araiyer
This is a probable solution: static int sec; int frand() { time_t seconds; seconds=time(NULL); sec = sec + ((int) seconds * rand()); //this sec is similar to sequential circuit in Digital Logic design return (sec); } -- Regards Saurabh Araiyer

[algogeeks] Re: random function

2011-09-19 Thread Don
You mean a pseudo-random generator. Without special hardware you won't get a real random generator. Use Mersenne Twister. Don On Sep 19, 9:43 am, prasanth n nprasnt...@gmail.com wrote: anyone give an algorithm of how to generate a random number..probability of occurrence of each no should be

Re: [algogeeks] Re: random function

2011-09-19 Thread abhinav gupta
for that u have rand() function in c programming just go through it On Mon, Sep 19, 2011 at 8:42 PM, prasanth n nprasnt...@gmail.com wrote: @don: suppose if give like random(5)- it must give any number between 0 and 5.. On Mon, Sep 19, 2011 at 8:22 PM, Don dondod...@gmail.com wrote: You

[algogeeks] Re: random function

2011-09-19 Thread Don
The most common way that it works would be that random(n) returns the equivalent of a random integer mod n, so 0=xn. But there is no standard for how they work, so know what you are dealing with. Don On Sep 19, 10:12 am, prasanth n nprasnt...@gmail.com wrote: @don: suppose if give like

[algogeeks] Re: random function

2011-09-19 Thread Don
The rand() functions built into many compilers are notoriously bad. If the quality of the random series doesn't matter much, it might be ok. If you are doing any kind of simulation, use Mersenne Twister. Don On Sep 19, 10:48 am, abhinav gupta abhinav@gmail.com wrote: for that u have rand()

Re: [algogeeks] Re: random function

2011-09-19 Thread Piyush Grover
as such there is no specific method to generate random number but if you have to implement it then you can generate a pseudo random generator using cur_time_value_in_mili_seconds mod n. On Mon, Sep 19, 2011 at 9:24 PM, Don dondod...@gmail.com wrote: The most common way that it works would be

Re: [algogeeks] Re: random function

2011-09-19 Thread abhinav gupta
int i; i=random(5); int random(int x) { return (rand(x) % 5); } rand() is inbuilt function in c/c++; On Mon, Sep 19, 2011 at 9:24 PM, Don dondod...@gmail.com wrote: The most common way that it works would be that random(n) returns the equivalent of a random integer mod n, so 0=xn. But