[Click] random

Bart Braem bart.braem at ua.ac.be
Tue Aug 7 09:37:28 EDT 2007


On Tuesday 07 August 2007 13:14, JS wrote:
> sorry to bother you again but I am still fighting to understand how the
> random function works in Click...
> I need to pick a random number between 0 and 1 and the only thing I have
> found about random at this time is in the RED element where they are using
> _random_value = (random() >> 5) & 0xFFFF;
> I guess this is a bit operation but I don't know what number is coming out
> of the random() function.
> So if anyone knows how to generate a number between 0 and 1 it would help
> me a  lot.

glue.hh has the follwoing code in it:
#if CLICK_LINUXMODULE
extern "C" {
extern uint32_t click_random_seed;
extern void srandom(uint32_t);
#define	RAND_MAX	2147483647
inline uint32_t
random()
{
    click_random_seed = click_random_seed*69069L + 1;
    return (click_random_seed ^ jiffies) & RAND_MAX;
}
}
#endif

That's for the linux module, but the behaviour for userlevel click is similar 
of course. So you get a random uint32_t which you can use to generate any 
random number using the classical techniques.

Bart
-- 
Bart Braem
PATS research group
Dept. of Mathematics and Computer Sciences
University of Antwerp
Campus Middelheim, G3.30
Middelheimlaan 1
B-2020 Antwerpen, Belgium
Phone: +32 (0)3 265.32.91
Fax: +32 (0)3 265.37.77
Web: www.pats.ua.ac.be/bart.braem
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 307 bytes
Desc: not available
Url : https://pdos.csail.mit.edu/pipermail/click/attachments/20070807/22c39bdf/attachment-0001.pgp


More information about the click mailing list