hi people i am working on a project where i need to generate random nos, lots of them. now til now i've been using the random() functio in C, but the thing is that when i run the program and call random() for the 1st time it goives a no say x1, and i terminate the program... now when i run it again, the random() functio returns the same no that is x1. i want to generate a random no that is random in the true sense of the word(lolz i hope u get what i mean...)
i have an idea, rather two 1. we can read some arbitrary data from the ram and convert that to a number 2. we can read some random file from the hard disk.
but the big question is HOW do i do all this? can someone help me with this?
or does someone have a better idea of generating random nos?
gurpreet __________________________________________________________ Great Travel Deals, Airfares, Hotels on http://r.rediff.com/r?www.journeymart.com/rediff/travel.asp&&sign&am...
Gurpreet Singh Student Final Yr Computer Sc. & Engg. --------------------------------------------------------------------- M A K E Y O U R O W N R O A D --------------------------------------------------------------------
----- Original Message ----- From: "Gurpreet Singh" tonysingh@rediffmail.com To: linuxers@mm.ilug-bom.org.in Sent: Wednesday, March 12, 2003 10:13 PM Subject: [ILUG-BOM] random no generation issues
hi people i am working on a project where i need to generate random nos, lots of them. now til now i've been using the random() functio in C, but the thing is that when i run the program and call random() for the 1st time it goives a no say x1, and i terminate the program... now when i run it again, the random() functio returns the same no that is x1. i want to generate a random no that is random in the true sense of the word(lolz i hope u get what i mean...)
*snip*
Just reading /dev/random as a file will give you a lot of insight ;). Hope it helps...
Regards,
-ah
Gurpreet Singh wrote:
i am working on a project where i need to generate random nos, lots of them.
Just say yes, yes, yes, no, yes, no, yes, yes, no, no, yes... make sure there's no easy pattern to it. Repeat several times till you have enough random nos.
now til now i've been using the random() functio in C, but the thing is
Ok, I get the idea. Use rand() instead, for portability. And you have to seed the random no. generator with, say, the current time. Seed it using srandom((unsigned) time(NULL)) before any calls to random().
i have an idea, rather two
<snip>
or does someone have a better idea of generating random nos?
Yes, read the manual for random(3), srandom(3), rand(3), etc.
-Manish
a yet another solution(for different granularity of generation time) wherein a unique random number can be generated more than once within a second......
struct timeval tv; gettimeofday(&tv, NULL); srandom((tv.tv_sec<<16)|(tv.tv_usec>>16)); uniquenum = random();
rgds, Rahul
Manish Jethani wrote:
Seed it using srandom((unsigned) time(NULL)) before any calls to random().
-Manish
On Wed, 12 Mar 2003, Manish Jethani wrote:
Ok, I get the idea. Use rand() instead, for portability. And you have to seed the random no. generator with, say, the current time. Seed it using srandom((unsigned) time(NULL)) before any calls to random().
Althought that is what I do, someone once said that it's a bad idea to seed the random number generator with the system time.
or does someone have a better idea of generating random nos?
Yes, read the manual for random(3), srandom(3), rand(3), etc.
Read Seminumerical Analysis by the Don. It'll pass on some insights into the theory of random number generation.
Remember, all generated random numbers are just pseudo random. If you really want a random number, stick your finger in the air, pick the molecule that lands in the very centre of the tip of your finger, and measure its vibration. Ensure it stays at the centre of your finger at this point.
Philip
Philip S Tellis writes:
On Wed, 12 Mar 2003, Manish Jethani wrote:
Ok, I get the idea. Use rand() instead, for portability. And you have to seed the random no. generator with, say, the current time. Seed it using srandom((unsigned) time(NULL)) before any calls to random().
Althought that is what I do, someone once said that it's a bad idea to seed the random number generator with the system time.
or does someone have a better idea of generating random nos?
especially if you use it to generate the key for encryption. For the attacker, it narrows down the search for the random number generated key.
from the random manpage (man 4 random): The random number generator gathers environmental noise from device drivers and other sources into an entropy pool. The generator also keeps an estimate of the number of bit of the noise in the entropy pool. From this entropy pool random numbers are created.
This is a good way to generate high quality random numbers.
Vinayak Hegde APGDST Student NCST-JUHU
Hi to generate the random number I would still suggest that you use rand() function given by C and use it nicely i.e effectively using seed so that you don�t get same no again and again. I used to use it in my good old collage days. And this function is still being used in most of the software even today
Second method is to divide a second, now whenever you press any key find out which milisecond part of that second take out its unit place and you get a brand new random number. This technique is used in developing an arcade game jackpot las vagas style
Third method is to use the system generated datetime stamp multiply the each individual number with each other and take out its unit place of the resultant
For some strange reason we have always been using time-space for finding out the unique random number
You Last full resort should be Get the no of ticks that your processor gives in a particular duration say 1 sec and get out its last unit digit, obviously your random number generation has to do with your processor speed
Thanks bye
--- Philip S Tellis philip@konark.ncst.ernet.in wrote:
On Wed, 12 Mar 2003, Manish Jethani wrote:
Ok, I get the idea. Use rand() instead, for
portability. And
you have to seed the random no. generator with,
say, the current
time. Seed it using srandom((unsigned)
time(NULL)) before any
calls to random().
Althought that is what I do, someone once said that it's a bad idea to seed the random number generator with the system time.
or does someone have a better idea of generating
random nos?
Yes, read the manual for random(3), srandom(3),
rand(3), etc.
Read Seminumerical Analysis by the Don. It'll pass on some insights into the theory of random number generation.
Remember, all generated random numbers are just pseudo random. If you really want a random number, stick your finger in the air, pick the molecule that lands in the very centre of the tip of your finger, and measure its vibration. Ensure it stays at the centre of your finger at this point.
Philip
-- Woman on Street: Sir, you are drunk; very, very drunk. Winston Churchill: Madame, you are ugly; very, very ugly. I shall be sober in the morning.
--
=====
__________________________________________________ Do you Yahoo!? Yahoo! Web Hosting - establish your business online http://webhosting.yahoo.com
Gurpreet Singh writes:
or does someone have a better idea of generating random nos?
open /dev/random as a file.
if ((fd = open ("/dev/random", O_RDONLY)) == -1) perror ("open error");
// key is an array
if ((read (fd, key, 16)) == -1) perror ("read key error");
for further details. man 4 random.
Vinayak Hegde APGDST Student NCST-JUHU
On Wednesday 12 March 2003 10:13 pm, Gurpreet Singh wrote:
hi people i am working on a project where i need to generate random nos, lots of them.
[snip]
i have an idea, rather two
- we can read some arbitrary data from the ram and convert that
to a number 2. we can read some random file from the hard disk.
but the big question is HOW do i do all this? can someone help me with this?
hi more ideas,
maybe you can read the data in /proc
lots of stuff to read actually, network data, interrupts occuring, time uptime, and so on.