This program simulates the random distribution of an inadequate supply amongst a group of entities.
Each entity has a chance, in turn, to take 1 or 0 from the supply - I call this WIN or LOSE respectively.
A WIN reduces the remaining supply for the turns that follow, a LOSE does nothing.
The probability of a WIN changes appropriately after each turn.
The probability must change in such a way that, by the end, the entire supply is consumed exactly.
With every LOSS probability increases; with every WIN probability decreases.
This is an experiment in writing such a program without the use of arrays.
remstart
This program simulates the random distribution of an inadequate supply amongst a group of entities.
Each entity has a chance, in turn, to take 1 or 0 from the supply - I call this WIN or LOSE respectively.
A WIN reduces the remaining supply for the turns that follow, a LOSE does nothing.
The probability of a WIN changes appropriately after each turn.
The probability must change in such a way that, by the end, the entire supply is consumed exactly.
With every LOSS probability increases; with every WIN probability decreases.
This is an experiment in writing such a program without the use of arrays.
remend
win = 1 : lose = 0
rem Let n equal number of entities + 1. Let s equal supply. Let p equal probability.
n = 21
p as float
do
cls
s = 5
for i = 0 to n-1
p = s/(n-i+.0)
`if p=1 or p=0 then pick=p else pick = rnd(1000)/1000.0 < p :`remmed out condition to demonstrate the pure maths works alone.
pick = rnd(1000)/1000.0 < p
dec s,pick :`only a WIN actually reduces supply.
y = i*16
text 0,y, str$(i)+"."
text 30,y, "Chance: " + str$(p)
text 220,y, " Result: " + str$(pick)
next i
text 0,y+32, "Press any key to run the experiment again."
wait key
loop
Does anyone know what the proper term for this type of probability where each action influences the next?