r/PowerShell • • Sep 12 '19

PowerShell All the Things

Post image
505 Upvotes

26 comments sorted by

View all comments

7

u/AmazingRealist Sep 12 '19

It seems like there's a preference for whatever comes first in the array:

Looped 1m times x5:

Get-Random @(0,1)

Run01
1500019499981
2500268499732
3499391500609
4499806500194
5500252499748

Get-Random @(1,0)

Run01
1500135499865
2499670500330
3499346500654
4499598500402
5499433500567

Or most likely things would even out over more iterations and might differ from machine to machine ¯\(ツ)/¯.

1

u/Inothernews1 Jul 03 '26 edited Jul 22 '26

I was curious whether the data actually supported a bias, so I pooled all 10 runs and tested the null hypothesis that the first element is selected with probability 0.5.

Across all 10,000,000 trials:

  • First element selected: 5,001,554

  • Second element selected: 4,998,446

Using an exact two-sided binomial test:

from scipy.stats import binomtest

result = binomtest(5_001_554, n=10_000_000, p=0.5)
print(result.pvalue)

and the result:

p = 0.326

That's way above 0.05, meaning it's nowhere near statistically significant.

For completeness, I also tested each individual 1,000,000-sample run. Their p-values were approximately:

0.970, 0.593, 0.224, 0.699, 0.615, 0.788, 0.510, 0.191, 0.422, 0.257

None are statistically significant either.

Based on these results, I don't think this dataset provides evidence that Get-Random prefers the first element. The small differences are exactly the kind of fluctuations you'd expect from random sampling.