pexels-photo-965875.jpeg

Photo by Jonathan Petersson on Pexels.com

The original function for this was to randomly pick a team mate to do a job task no one wanted to do. The team stated they wanted to be “fair” (aka lazy and leave it up to lady luck\chance). Originally this stated with two 6 sided dice. However I found that 6-9 where heavily favored. One 10 sided die didn’t feel random enough, so I wrote a simple function. Since I was going through a python course and kept adding to it and now you get the over-written function below.

This is written in python 3 on jupyter.

Apologies that wordpress totally messed up the formatting. You’ll have to fix that.

import random
#list of people currently out

,'Z'

#currently available
ogteamList = ['A','B','C','D','E','F','G','T','M','V','R','J','L','Y']
teamList = ogteamList
tm = 0
chanceList = []
#When True this option shows the stats during the shuffle. Set to False to just pick a person
nerd = True

#dynamically create the chanceList length based on ogteamList length
while tm < len(ogteamList):
chanceList.append(0)
tm=tm+1

#y=number of times to shuffle teamlist. Anything beyond 10000 will eat your CPU.
#Standard Deviation does get smaller the higher y is. I feel the lower this number the more random it is.
y=1000
i=0

#the main function of this is the shuffle of the teamList
#the sub function is to track the percentage of picks for us data nerds
while i < y:
random.shuffle(teamList)

if nerd:
#choose random person
rando = random.choice(teamList)
tm = 0

#track how many time the person was picked throughthe shuffle of y
while tm < len(ogteamList):
if rando == ogteamList[tm]:
chanceList[tm] = chanceList[tm]+1
tm=tm+1
i=i+1

if nerd:
#no need to import if not a nerd, so this is here to "conserve memory"
import statistics as stat
#set chance list to the % each person as picked randomly through the shuffle of y
tm = 0
stdDev = stat.stdev(chanceList)
while tm < len(chanceList):
chanceList[tm] = chanceList[tm]/y
tm=tm+1


#print the % of times choosen during the shuffle
print(chanceList)
print('Standard Deviation =',stdDev)

#pick a random person and print their name
print('Lucky person =',random.choice(teamList))

Hope this helps someone else out to be ‘random’.