Last active
December 1, 2017 01:00
Revisions
-
fynntimes renamed this gist
Dec 1, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
fynntimes created this gist
Nov 30, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ # Faizaan Datoo Pd3 # A very simple example of using technology to automate simulations :) # I /could/ have made it more complicated, but that would defeat the point! import random print "Enter a range of digits." # Get those numbers... minVal = input("\tYour minimum value: ") maxVal = input("\tYour maximum value: ") repetitions = input("\tAmount of repetitions: ") ignoreRepeats = raw_input("\tIgnore repeats? (y/n): ") print "Okay, crunching some numbers..." tries = [] for i in range(repetitions): print "=== Repetition #" + str(i + 1) + " ===" times = 0 history = [] while True: # Generate random values, print them out generated = random.randrange(minVal, maxVal) # Check for duplicates if we have to! if ignoreRepeats == "y": while (generated in history): generated = random.randrange(minVal, maxVal) history.append(generated) print str(generated) + " ", # Increment the times value to show we chose another guy times += 1 # If it's less than 8 (i.e. 01 to 07), we got it, so end the repetition if(generated < 8): print "| " + str(times) + " tries" tries.append(times) break # Get the mean and print it, we're done mean = sum(tries) / float(len(tries)) print "It took an average of " + str(mean) + " tries overall."