PDA

View Full Version : Source code of C rand function



mecrazycoder
January 20th, 2011, 08:56 PM
hi,
Please let me know where can I get the source code of actually implementation of C rand() function. I checked in coreutils but it is not there. Thanks in advance

geirha
January 20th, 2011, 09:38 PM
It's in the standard C library, so:

apt-get source libc6

You'll have to dig a little to find the actual code, but eglibc-2.11.1/stdlib/rand.c should be a good start.

geirha
January 20th, 2011, 09:53 PM
It's in the standard C library, so:

apt-get source libc6

You'll have to dig a little to find the actual code, but eglibc-2.11.1/stdlib/rand.c should be a good start.

mecrazycoder
January 21st, 2011, 03:46 PM
It's in the standard C library, so:

apt-get source libc6You'll have to dig a little to find the actual code, but eglibc-2.11.1/stdlib/rand.c should be a good start.
Thank you

Arndt
January 21st, 2011, 03:51 PM
You may want to look at 'random' and 'drand48', too.

Simian Man
January 21st, 2011, 03:54 PM
The rand function included in libc is actually pretty bad. I don't know what you are asking for, but there are much better implementations out there on the net.

psusi
January 21st, 2011, 04:08 PM
If you want cryptographically strong random numbers, you want /dev/random. If you don't care THAT much, then rand() is just fine.

Arndt
January 21st, 2011, 04:25 PM
If you want cryptographically strong random numbers, you want /dev/random. If you don't care THAT much, then rand() is just fine.

As a blanket statement, no, not really, but if you first determine what kind of properties are important for your application and test 'rand' for those to your satisfaction, then all will be fine.