On Sat, Dec 15, 2001 at 06:14:37PM +0800, you (Liu Wen) wrote: > Generating random numbers has always been a big problem. You're deadly right. >From the programmer point of view, there exists a few ways to go. In Ansi C the simplest method is: srand(getpid()); printf("%d\n", rand());
Not too much, but harder is: srand( <getpid()/getuid()/whatever> ); printf("%d\n", rand()>>rand()); You are able to do very complicated combinations. In perl you're able to use special(really good) modules from CPAN like Math::Random and Math::TrulyRandom. In Python you'll find random module equiped in various variations(Expotential, Gaussian, Gamma, Pareto, Weibull and so on) In one of my applications written in C I have used simple mechanism of srand with value passed by user in the command line. It's available at my homepage and it's named snfc, and function for generating random number looks like below: ----------- char *generate_key(int userval) { int ziarenko; char *key; key=malloc(100); srand((time(NULL)/userval)); ziarenko=rand(); snprintf(key, 11, "%d", ziarenko); return key; } ----------- userval is passed in the command line by user, it could be any integer value, it depends of the user. * I know, all of these numbers genereated are pseudo random, but I think that we can call them random, it's always less letters to write :) * Other sources: 1) if you're programming in bash, you could take a look at "Advanced Bash Scripting HOWTO" 2) c programmers: <http://www.eskimo.com/~scs/C-faq/top.html> sorry, but my small brain is really to small to remaind me more links... ;) Usenet: Groups: news://sci.crypt.random-numbers news://alt.numbers.random (does anybody hear me ? ;)) Discussions: Message IDs: <[EMAIL PROTECTED]> <9go7kj$eov$[EMAIL PROTECTED]> <XdZB7.1291$[EMAIL PROTECTED]> <gEXL7.483$[EMAIL PROTECTED]> <[EMAIL PROTECTED]> HTH. -- [ Wojtek gminick Walczak ][ http://hacker.pl/gminick/ ] [ gminick (at) hacker.pl ][ gminick (at) klub.chip.pl ]