On Mon, Jun 07, 2004 at 03:48:08PM +0200, Sven Schuster wrote: > > Hi Amit, > > On Mon, Jun 07, 2004 at 06:53:57PM +0530, aksingh@hss.hns.com told us: > > > > Hi > > > > How about net_random() and net_srandom()(in net/core/utils.c), theyre also > > random number generators, any suggestions as to which is better > > get_random_bytes () or any of these ? > > Well, after taking a short look at what net_random() and net_srandom() > do I'd say that get_random_bytes() does a better job (i.e. better > random values), at least it seems like to me. net_(s)random() take > net_rand_seed as a base, which is initialized to 152, do some > multiplication and return net_rand_seed ^ jiffies, which results in > a monotonically increasing value (ok, there's of course an overflow > of net_rand_seed). But no more "real" randomness. OTOH, get_random_bytes() > gets it's random numbers from the entropy pool which should give you > better random numbers. Just my opinion, of course, maybe I have > overlooked something. > > > Thanks Sven, but would a & not be better than a % to get a value between 0 > > and my max value, i.e i can do a (get_random_bytes_returned & max_value). > > Does this in anyway reduce randomnness ? > > Both should basically be the same I think. > I think (get_random_bytes_returned & max_value) will give you proper results only if max_value = (2^n)-1. for example if max_value = 4 you will either get 4 or 0 as output. If its 3 you will get 0-3. I don't know about these specific methods, but take note that at least with some of the random number generation methods (usually the faster ones), the least significant bits tend to be not very random, sometimes the most significant bits also have the same problem, so if you don't want the full range, usually you will get the best results from taking your bits from the middle (using shift, something like ((get_random_bytes_returned >> 2) & ~0xf) % max_value) > > Sven > > > Any suggestions are welcome. > > > > thanks > > Amit > > > > -- > Linux zion 2.6.7-rc2 #2 Mon May 31 22:58:01 CEST 2004 i686 athlon i386 GNU/Linux > 15:39:41 up 6 days, 16:39, 3 users, load average: 0.00, 0.00, 0.00 -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/