From: Dennis S. <sy...@yo...> - 2004-10-02 11:35:24
|
I've put some of the randomness request in CVS, not yet finished tho. Cheers, Dennis |
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 |
From: Dennis S. <sy...@yo...> - 2004-10-03 16:13:16
|
On Sun, 2004-10-03 at 18:48 +0300, Vitaly V. Bursov 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... Go ahead :) > 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 Thanks for the demo program and for pointing this out, it has been fixed in CVS. Cheers, Dennis |
From: Vitaly V. B. <vit...@us...> - 2004-10-03 17:00:48
|
On Sun, 03 Oct 2004 18:11:35 +0200 Dennis Smit <sy...@yo...> wrote: > On Sun, 2004-10-03 at 18:48 +0300, Vitaly V. Bursov 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... > > Go ahead :) OK :) few bits of code.... ========================== #include <stdlib.h> #include <stdio.h> #include <string.h> #define val_a 1664525L #define val_c 1013904223L #define RMAX 4294967295U static unsigned int _lv_randseed = 5415454; double rnd() { #if 0 union { unsigned int a[2]; double d; } val; unsigned int t; /* EXECUTION TIME * alu maths = 5 clocks * fsub = 4 clocks * TOTAL: 9 for double * WARNING: numbers should be ieee754 compliant */ t = _lv_randseed = val_a * _lv_randseed + val_c; val.a[0]=(t<<20); val.a[1]=0x3ff00000U | (t>>12); return (*(double*)&val.d)-1.0; #else unsigned int t; double x; /* EXECUTION TIME * fild - load int to fpu = 4 clocks * fdiv - normalize result = 16/20/24 clocks for signle/double/ext prec. * TOTAL: 24 for double */ t = _lv_randseed = val_a * _lv_randseed + val_c; x = (double)t/RMAX; return x; #endif } double x = 0.0; int main() { unsigned int i, t=1000000000; for (i=0;i<t;i++){ x += rnd(); } } ========================== the same idea can be used to generate floats. should I make a patch? -- Vitaly GPG Key ID: F95A23B9 |
From: Dennis S. <sy...@yo...> - 2004-10-03 17:25:02
|
On Sun, 2004-10-03 at 19:55 +0300, Vitaly V. Bursov wrote: > the same idea can be used to generate floats. > > should I make a patch? Yeah sure, go ahead :) Cheers, Dennis |
From: Vitaly V. B. <vit...@us...> - 2004-10-03 22:39:16
Attachments:
rnd.diff
|
Here we go!... Dennis, do you have some app to test this random() stuff? -- Vitaly GPG Key ID: F95A23B9 |
From: Dennis S. <sy...@yo...> - 2004-10-04 17:12:25
|
2004-10-04 Dennis Smit <ds...@ne...> * libvisual/lv_random.*: A bit of a overhaul by Vitaly V. Bursov, thanks Vitaly :) (owyeah also added double, float) Thanks a lot Vitaly, looks really good, I love how you've solved the things with the #defines :) I changed a few things, take a look at CVS. Cheers, Dennis On Mon, 2004-10-04 at 01:37 +0300, Vitaly V. Bursov wrote: > Here we go!... > > Dennis, do you have some app to test this random() stuff? > |