Glib rand() revisited: RAND_MAX?




	Should g_rand_int() (in CVS) have an equivalent of RAND_MAX
#defined?  (it would just be the highest number a guint32 can hold)

	I have seen (and am trying to duplicate :) code that 'flips a
coin', and it looks like this:

if ( rand() < RAND_MAX/2 ) {
	side = heads;
}
else {
	side = tails;
}

	Is there a cleaner way to choose a random TRUE/FALSE value?  I was
thinking of doing:

g_rand_int_range(rand, 0, 1)

	...but that really seems like overkill.

	Please note that I'll need to call this many, many times so speed
is an issue (and is another reason I don't want to use
g_rand_int_range()).

	Any help is greatly appreciated.


Thank You,
Derek Simkowiak
dereks@kd-dev.com



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]