Hello, On Sun, Mar 21, 2010 at 11:27:19PM +0100, Joachim Breitner wrote: > > What is the correct way to initialize the seed? > I was wrong about that, xscreensaver must somehow already take care of this. (I tried adding "srandom(time(NULL))" to unicode_init() but there's an error indicating that this shouldn't be done inside the screensaver code for xscreensaver screensavers.)
Now I'm left completely puzzled as I do believe that there's something weird about the screensaver's randomness. I spent quite some time watching it and some chars occoured way too often -- while using arc4random from above most chars I saw where unknown to be beforehand... I tried a "modulo bias" workaround that was suggested here [1] using code from here [2] and tried to capture some data with minimal examples of both versions with the numbers from unicode-screensavers (max=3092 and 5121) and compared their histograms but I couldn't find anything significant there, what increases my confusion. [1] http://stackoverflow.com/questions/648739/objective-c-modulo-bias [2] http://stackoverflow.com/questions/1322510/bit-twiddling-find-next-power-of-two Sorry for the noise in case there actually is no "objective" bug... Greetings, Stephan PS: The workaround: --- unicode.c | 22 ++++++++++++++++++++-- 1 files changed, 20 insertions(+), 2 deletions(-) diff --git a/unicode.c b/unicode.c index 3c19244..3bae494 100644 --- a/unicode.c +++ b/unicode.c @@ -30,6 +30,18 @@ struct unicode_state { XColor bg_color; }; +int next_power_of_two(unsigned int n) +{ + n--; + n |= n >> 1; + n |= n >> 2; + n |= n >> 4; + n |= n >> 8; + n |= n >> 16; + n |= n >> 32; + return ++n; +} + static void * unicode_init (Display *dpy, Window window) { @@ -125,12 +137,18 @@ unicode_draw (Display *dpy, Window win, void *void_state) { struct unicode_state *state = (struct unicode_state *)void_state; if (state->blank) { + int y,count; XWindowAttributes xgwa; XGetWindowAttributes (dpy, win, &xgwa); font = random() % NUM_FONTS; - pickn = random() % state->font_count[font]; + count = state->font_count[font]; + y = next_power_of_two(count); + pickn = random() % y; + while (pickn >= count) + pickn = random() % y; + printf("pickn: %d\nmax: %d\nnext: %d\n",pickn,count,y); pickc = 0; for (ucs4 = FcCharSetFirstPage (state->fonts[font]->charset, map, &next); -- 1.7.0.2 -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org