#!/usr/bin/env python # ----------------------------------------------------------------------------------- # # Python/ROOT script testing randomness of single digits (i.e. [0-9]). # # Author: Troels C. Petersen (NBI) # Email: petersen@nbi.dk # Date: 16th of September 2014 # # ----------------------------------------------------------------------------------- # # Load modules here from ROOT import * # ----------------------------------------------------------------------------------- # # Reading data files: # ----------------------------------------------------------------------------------- # # Write extensive output verbose = True # Define list of input files infiles = ["./data_RandomDigits2014A.txt"] # List containing all numbers numbers = [] # Loop over input files open them in read mode for ifile in infiles : with open( ifile, "r" ) as current_file : # Extract current file info : loop through each line in the file, loop through each character # in the line, demand character is not empty ("") and convert the result to an integer # Finally add result to the numbers list numbers += [int(char) for line in current_file for char in line.strip() if char is not ""] # Print out your numbers, to see everything works correctly if verbose : for i, inumb in enumerate( numbers ) : print "%d"%(inumb), if (i%50 == 49 and i > 0) : print "" print print "The total number of digits is ", len(numbers) # ----------------------------------------------------------------------------------- # # Your analysis: # ----------------------------------------------------------------------------------- # # ----------------------------------------------------------------------------------- # # # First look at the random digits, and see if you see any patterns? Probably not, mostly # because there are many numbers, and patterns of this kind are not that visible to the # human eye. So, you will have to work a bit... with statistical tests. # # Before even looking at the above program, think about what statistical tests you # could submit the sample to. Then consider, how to actually carry out these tests. # We will try in class to compile and discuss a list, before we start working on it!!! # # Finally, I've been so kind to put three data samples for 2014! One is from the random # number generator TRandom3, one is a series of digits from pi, and one is from the 50 # digits that all of you put into the questionaire! Try to find out, which one is human, # and which two are from mathematics/computers. # # # Questions: # ---------- # 1) Are each digit represented roughly equally many times? Try to count/plot the # frequency of each digit, and ask yourself what the chance is, that they come # from a uniform distribution. # # 2) Are there as many even as odd numbers? How about low (0-4) vs. high (5-9) numbers? # And do people have a tedency to choose an even number after an odd and vice versa? # And similarly for low/high numbers. # # 3) Are people "afraid" of putting the same digit twice in a row? And how about three # or four identical digits in a row? How many would you expect to have of these, and # how many do you observe? # # 4) Try to count, which digits follows which digits. That should be 100 counts in total. # If the numbers were truly random, what would you expect then? Is that what you # observe? Can you test this for example with a Chi-Square (think about how many # entries you expect in each bin) and/or a likelihood? # # 5) Do you throughout the above process find out, which sample you contributed to? # How certain are you? # # Advanced: # 6) Were the students of 2011, 2012 and 2013 better or worse at picking random numbers? # # ----------------------------------------------------------------------------------- #