May 21, 2011

Semi-random Math.Random()

I'm not so sure that the Flash random number generator has quite the flat distribution you'd really like from it. Not so much the pseudo-random sequence, as the way they seed it. I know that I've seen a handful of pictures multiple times in the new top-rotation flash. (It isn't a rotation any longer, but I'm used to calling it that and I'm going to keep doing so.)

I've been thinking about adding the number of seconds since the previous midnight to it and then taking the modulo of the result for the image selection, as a way of making it a lot more even.

Sorry for posting about something this trivial, but I don't have anything else to say today.

Looks like the world didn't end, for one thing.

Posted by: Steven Den Beste in Site Stuff at 03:37 PM | Comments (16) | Add Comment
Post contains 132 words, total size 1 kb.

1 My math-fu is weak these days, but I've had bad luck reseeding pseudo-random functions instead of just seeding them once at program start.  In my experience it seems to introduce quirks, such as favoring certain number ranges, or even producing pairs of numbers that often appear one after the other.

Posted by: Siergen at May 21, 2011 04:42 PM (k6F1L)

2 I would not do anything without collecting data first (e.g. a vector of counters for each picture). I haven't seen many dublicates during my visits, maybe even none. The set is small, dups are unavoidable, and your mind may be playing tricks on you.

Posted by: Pete Zaitcev at May 21, 2011 05:09 PM (9KseV)

3

I'm not talking about reseeding. I'm talking about using the number of seconds since midnight, modulo the number of images, in addition to a random offset.

Taking a histogram would be a pain, because the problem looks like the way that they are seeding. So I'd have to store it in a file, and then invoke the test program hundreds of times.

Posted by: Steven Den Beste at May 21, 2011 06:02 PM (+rSRq)

4 Pete, you may be right that I'm borrowing trouble.

Posted by: Steven Den Beste at May 21, 2011 06:02 PM (+rSRq)

5 Why not just use the number of seconds and skip the pseudorandom generator entirely? To eliminate bias from people checking at around the same time every day, just use the number of seconds since the system time epoch modulo the number of images.

Posted by: Boviate at May 21, 2011 06:53 PM (RPpft)

6

Boviate, that would mean that if someone reloaded the site several times in close succession, they'd get a series of pictures from the same series.

Folks, this post was not a request for suggestions.

For the time being I'm not going to change anything.

Posted by: Steven Den Beste at May 21, 2011 06:59 PM (+rSRq)

7 Looks like the world didn't end, for one thing.

Are you sure it didn't?

Posted by: Wonderduck at May 21, 2011 09:23 PM (n0k6M)

8 This reminds me of how the BSD 4.x fortune program worked: when you built the indexed data file, it shuffled the fortunes once, and then wrote a counter into the file. Every time someone ran the program, it incremented the counter. This turned out to be really painful when 100 workstations mounted the same /usr/games partition, and everyone's dotfiles included a fortune call.

-j

Posted by: J Greely at May 21, 2011 11:49 PM (2XtN5)

9 I finally saw closely spaced duplicates. They happen, and one who still remembers C-by-n-out-of-m can probably calculate the probability.

Also, I found a link that used to be in the image: there's an equivalent "Home" link in the navigation area on the top right.

Posted by: Pete Zaitcev at May 24, 2011 08:16 AM (9KseV)

10 Actually, now that I think about it, every time you reload the page you're getting a fresh instance of the SWF, so you're always using the first random number generated from a particular seed. Poorly-chosen seeds would produce very un-random results.

-j

Posted by: J Greely at May 24, 2011 08:51 AM (2XtN5)

11

J, exactly so. (Except that I make 12 calls to the random function and throw them away, using the 13th for the image choice.)

Pete, the "Chizumatic" logo on the flash is the link you're looking for. Clicking that takes you to the base page of this site.

I'm reserving the rest of the flash display space for future expansion. I may want to put other controls in there some day.

Posted by: Steven Den Beste at May 24, 2011 09:05 AM (+rSRq)

12 Ah, lucky 13! I think varying the number of results you throw away each time would be the simplest improvement. Maybe let the RNG run in a loop for half a second or so?

-j

Posted by: J Greely at May 24, 2011 10:03 AM (2XtN5)

13 So, any complaints from iPad users yet? J?

Posted by: Pete Zaitcev at May 26, 2011 07:17 PM (9KseV)

14 What's an iPad?

-j

Posted by: J Greely at May 26, 2011 08:41 PM (2XtN5)

15

It's like my Slate, only worse.

Posted by: Steven Den Beste at May 26, 2011 09:47 PM (+rSRq)

16 I expect iOS users who care about being able to see the top rotation would come to the blog less often or stop reading it entirely. IOW, no downside?

Posted by: AlexG at May 27, 2011 07:42 AM (FD/w9)

Hide Comments | Add Comment

Enclose all spoilers in spoiler tags:
      [spoiler]your spoiler here[/spoiler]
Spoilers which are not properly tagged will be ruthlessly deleted on sight.
Also, I hate unsolicited suggestions and advice. (Even when you think you're being funny.)

At Chizumatic, we take pride in being incomplete, incorrect, inconsistent, and unfair. We do all of them deliberately.

How to put links in your comment

Comments are disabled. Post is locked.
11kb generated in CPU 0.0099, elapsed 0.0195 seconds.
20 queries taking 0.0131 seconds, 33 records returned.
Powered by Minx 1.1.6c-pink.