Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

percentages

Name: Anonymous 2011-11-09 20:15

Help /prog/ I suck at maths.

I have a range of countries with associated percentages.

How can I base an if condition around that percentage so if I have Switzerland at 44%, there is a 44% chance of evaluating to Switzerland.

Name: Anonymous 2011-11-09 20:59

>>6
PRNG will be PRNG (My implementation is SBCL which uses some optimized version of MT19937(Mersenne twister)).


(defun mean (sequence) (/ (reduce #'+ sequence) (length sequence)))

CL-USER> (loop repeat 5 collect (mean (loop for i from 1 to 10 collect (random 1.0))))
(0.5666071 0.45750922 0.53701687 0.48007727 0.70273066)

As you can see, given n=10 samples, it can sometimes go quite far from the ideal average of 0.5.
The larger number of samples, the smaller the deviation

CL-USER> (loop repeat 5 collect (mean (loop for i from 1 to 1000 collect (random 1.0))))
(0.49154118 0.48997444 0.50767094 0.48656407 0.48607567)
CL-USER> (loop repeat 5 collect (mean (loop for i from 1 to 100000 collect (random 1.0))))
(0.4987231 0.50044996 0.49934453 0.500932 0.50077873)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List