From: Vitaly V. B. <vit...@us...> - 2004-10-03 15:49:19
|
On Sat, 02 Oct 2004 13:35:13 +0200 Dennis Smit <sy...@yo...> wrote: > I've put some of the randomness request in CVS, not yet finished tho. when you convert unsigned int to float you loose entropy... I think it's ok to add double variant of functions... and one more thing... regarding to visual_random_int_range() we should not use modulo operation unless we want to get _short_ repeating sequence. This function will be used mostly (i think) to select some config profile like load_new(configs[visual_random_int_range(0, sizeof(config)/sizeof(*config)-1)]); we must use division op. here. smth like uint32_t visual_random_int_range (int min, int max) { return (visual_random_int () / (RANDOM_MAX/(max - min + 1))) + min; } Yes, it's slow but works better. To check it compile&run =============== #include <stdlib.h> #include <stdio.h> #include <string.h> #define val_a 1664525L #define val_c 1013904223L #define RMAX 4294967295U #define X (1<<3) static unsigned int _lv_randseed = 5415454; unsigned int rnd() { unsigned int a; a = _lv_randseed = val_a * _lv_randseed + val_c; a = a%X; // a = a/(RMAX/X); return a; } int main() { unsigned int i, t=256; for (i=0;i<t;i++){ printf("%d ", rnd()); if (i%X == 0) printf("\n"); } } =============== ;) -- Vitaly GPG Key ID: F95A23B9 |