How random is this?

Bluevoss
I'm using the random number generators I see elsewhere in this forum. Usually it's in the form of this...

    var rnd=Math.ceil(Math.random()*5);
squiffy.set("rnd",rnd);


This always appears at the top of the needed section.

Reason I ask, I've got a number of random parts in my adventure that seem to weight funny - I'll see one respond one-in-four something like four times in a row. Seems odd.

Anyone else see this? I feel like I'm playing Yahtzee over the phone with a cheater.... :?

Dennis Carlyle
Seems to work fine, as far as I can see.

Apparently it's pretty normal to see 'patterns' in these things -- not because it isn't working, but because random series will almost always have clusters. (And because we instinctively look for patterns.) They can seem odd at first, but if you were to run your code above 1000 times, clusters would occur, but things would even out over the entire series. (Not entirely, though. As I understand it, getting each of the five numbers to come up *exactly* 20% of the time would be somewhat unusual - maybe once in 10 / 100 ? tries.)

Bluevoss
Thanks for the confirmation. I've run skeleton versions of code, just making sure I could reuse random variables across different sections. Seems to work just fine. But I'll be playing my game and seeing the same 1-in-4 shot come up over and over, and that's just odd.

Bluevoss
Found it.

In one of the worst offenders in my game, there was a 1/6 chance of the failure path. In three runs, I failed each time.

And here was the code (modified off my original post)

    
var rnd=Math.ceil(Math.random()*5);
squiffy.set("rnd",rnd)


I just saw it. The set function was missing the ; so it never got executed (or just ran wrong). I put the semi in and it works just fine now.

Bluevoss
I take this back. Why it seems to work now, I don't know. I ran this both ways on my test bench and saw it work correctly either way, semi or no.

I just can't believe that run of luck. It seems, I dunno, questionable.

This topic is now closed. Topics are closed after 180 days of inactivity.

Support

Forums