March 02, 2012
I recently noticed that I almost never saw any pictures from Sengoku Otome, even though there are 48 of them out of 994. I had the feeling I'd seen pictures from Maken Ki more often, though there are only about half as many.
It's the damned flash random number again. Sengoku Otome is the last in the list, so it would correspond to highest possible random numbers, and I think the distribution disfavors the very highest part of the continuum. So this morning I had an idea, and made another change to the code, which I think will help. As always, if you want the new one you need to clear your browser cache. It shouldn't be a huge difference, but it may be a little different.
(If you're curious, I multiplied the random number by 7 and then took it modulo 1, in hopes of evening out the distribution a bit more.)
Posted by: Steven Den Beste at March 02, 2012 02:52 PM (+rSRq)
Posted by: J Greely at March 02, 2012 03:06 PM (2XtN5)
Problem is, I don't know what it would be. The only thing like that reasonably available to me is the time of day, and I'm already using that.
Theoretically it's available at the level of milliseconds but it doesn't really have that granularity. I'm currently using it at the level of seconds.
The current formula is this:
a = (rand()*7) % 1;
b = a * num_pictures;
c = num seconds since midnight;
d = (b + c) % num_pictures;
and then I use d to select it.
That 7 in the first line is what I added today, in hopes of smearing out the curve a bit more.
Posted by: Steven Den Beste at March 02, 2012 03:16 PM (+rSRq)
Posted by: J Greely at March 02, 2012 04:28 PM (2XtN5)
An expert probably could. I don't know how. Actionscript is a black art and most of what I've picked up has just been from messing around, and imitating things I found in other flashes that I decompiled.
What I've got now isn't intolerable, so I'm not rabid to find a solution.
Posted by: Steven Den Beste at March 02, 2012 05:28 PM (+rSRq)
Part of the problem is that Adobe's documentation ranks down there with the kind of documentation you get with open source software. It's mostly organized as a reference guide.
There are tutorials, but they're hopeless. I tried working through one of them, and it didn't work the way they said it would.
At least back in the days of flash 8, you got a local copy of the documentation. These days it's on Adobe's web server. Supposedly you can down load them, but when I try it takes forever and never completes.
I wonder if there's a "Stupid guy's guide to Actionscript" available for the Kindle?
Posted by: Steven Den Beste at March 02, 2012 05:53 PM (+rSRq)
How about a better random number generator?
https://github.com/skyboy/AS3-Utilities/blob/master/skyboy/utils/Random.as (Mersenne Twister in AS3)
Posted by: RickC at March 02, 2012 05:56 PM (/5bLf)
The problem here isn't the random number generator. The problem is how it gets seeded. That AS is using the time-of-day as a seed, which is typical.
I'm virtually certain that's how the Math.random() function is getting seeded. So it wouldn't be any different.
Coming up with a reasonable seed is a lot more difficult than you might think. There was a case a few years ago where some supposedly-secure protocol got cracked because it turned out that it was using the time-of-day as part of choosing its session key. So nominally the key search space was unfathomably immense, but in practice it was pretty small if you knew about when the communication session began.
There's a guy, turns out to be the nephew of John Colicos, who claims to have developed a way of creating true random numbers using standard PC hardware. But I doubt that Adobe has licensed it.
Posted by: Steven Den Beste at March 02, 2012 07:01 PM (+rSRq)
Posted by: Steven Den Beste at March 02, 2012 07:02 PM (+rSRq)
Posted by: benzeen at March 02, 2012 08:05 PM (R9i5E)
Essentially, what he's doing is trying to convert a single not-terribly-random number in the range 0-86400 into a plausibly-diverse index into an array of size N. The built-in PRNG is just a convenient hash function, so that the image generated at time T+1 isn't too similar to the image from time T.
If only ActionScript had a built-in function like CurrentWindSpeedInCanberra()...
Posted by: J Greely at March 02, 2012 08:11 PM (2XtN5)
That's exactly right. No matter how you add it up, a pseudo-random-number-generator is just a function applied to the seed, if you only call it once -- which is the case here. The real randomness is the seed, and there just aren't that many things you can use for that.
Back in the DOS days, they used to include things like the current mouse pointer position, and how long it had been since the last character on the serial port, and stuff like that. But you can't really use those any more. (Serial port? What's that?)
The PRNG is just a hash function for the seed value, is what it amounts to.
I suppose I could use the raw time value, and multiply it by something like 137, and then take the modulo by the number of pictures. Maybe I'll do some experimenting.
Posted by: Steven Den Beste at March 02, 2012 08:25 PM (+rSRq)
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.
21 queries taking 0.0107 seconds, 29 records returned.
Powered by Minx 1.1.6c-pink.