RandomInt - Penchant for large numbers?

Post » Thu Sep 18, 2014 6:12 am

I'm implementing code that is chance-based, so I'm using RandomInt(1,100) to roll for the success/failure check. However, it seems that RandomInt loves to pick numbers between 90 and 100, to the point that I get those way more often than anything else. At first I thought it was just a statistical anomaly due to a small sample size, but then I tried printing ten thousand rolls into the Papyrus log and more than a third of them were >90.

Am I just being a victim of uncommon odds? Is there something about the way that RandomInt generates results that makes it have a tendency towards higher numbers? And lastly, would I get better results with RandomFloat instead?

User avatar
Kari Depp
 
Posts: 3427
Joined: Wed Aug 23, 2006 3:19 pm

Post » Thu Sep 18, 2014 3:53 pm

There was a thread about this recently that determined there is nothing wrong with papyrus random number generation. However, I just ran a quick test myself for the heck of it. Here is the output I got:

randInt(0, 99) testrandInt between 0 and 9  -  369 times.randInt between 10 and 19  -  355 times.randInt between 20 and 29  -  356 times.randInt between 30 and 39  -  359 times.randInt between 40 and 49  -  360 times.randInt between 50 and 59  -  344 times.randInt between 60 and 69  -  398 times.randInt between 70 and 79  -  400 times.randInt between 80 and 89  -  378 times.randInt between 90 and 99  -  369 times.
User avatar
LuBiE LoU
 
Posts: 3391
Joined: Sun Jun 18, 2006 4:43 pm

Post » Thu Sep 18, 2014 6:34 am

Huh... I just ran another two large tests and my results are very close to yours. I guess that was just one hell of a coincidence. Thanks!

User avatar
Bereket Fekadu
 
Posts: 3421
Joined: Thu Jul 12, 2007 10:41 pm


Return to V - Skyrim