# script throwDice.py ''' throwDice simple example to produce random numbers 1, 2, ..., 6 as obtained by throwing dice .. author:: Guenter Quast ''' # pyhton2 - python3 compatibility from __future__ import division from __future__ import absolute_import from __future__ import print_function from __future__ import unicode_literals # import numpy as np ndice=1 # number of dice nthrow=30 # how often to throw numbers=[] for i in range(nthrow): r=0 for j in range(ndice): r += int(6*np.random.rand()+1.) numbers.append(r) print (numbers) oname='dice.dat' np.savetxt(oname,numbers) # throw undistinguishable quantum dice if(ndice>1): qnumbers=[] for i in range(nthrow): r=0 while r==0: q=[] for j in range(ndice): q.append(int(6*np.random.rand() )+1) # accept only one permutation (the one with q[i+1] >= q[i]) if all(np.greater_equal(q[1:],q[:-1])): r+=np.sum(q) qnumbers.append(r) # end while print (qnumbers) oname='qdice.dat' np.savetxt(oname,qnumbers) # end if(ndice<=1)