In [8]:
import numpy as np
import multiprocessing
import time

In [9]:
np.random.seed()
#np.random.seed(time.time())


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
mtrand.pyx in mtrand.RandomState.seed (numpy/random/mtrand/mtrand.c:7740)()

TypeError: 'float' object cannot be interpreted as an integer

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-9-f0d80ebac8d9> in <module>()
      1 np.random.seed()
----> 2 np.random.seed(time.time())

mtrand.pyx in mtrand.RandomState.seed (numpy/random/mtrand/mtrand.c:7962)()

TypeError: Cannot cast array from dtype('float64') to dtype('int64') according to the rule 'safe'

In [7]:
u1 = np.random.uniform() #0., 1.
print(u1)
u2 = np.random.uniform(u1, 1.0)
print(u2)
u3 = 1.0 - u2
print(u3)


0.7679233338828652
0.864746160895032
0.13525383910496802
$$\left<u_3\right> = \frac{1}{1-0}\int_0^1{du_1}\frac{1}{1-u_1}\int_{u_1}^1{du_2}\frac{1}{1-u_2}\int_{u_2}^1{u_3}{du_3}$$\begin{eqnarray} &=& \frac{1}{2} \end{eqnarray}
\begin{eqnarray} &=& \frac{1}{2}\int_0^1{du_1}\frac{1}{1-u_1}\int_{u_1}^1{du_2}\frac{1}{1-u_2}\left(1^2-u_2^2\right) &=& \frac{1}{2}\int_0^1{du_1}\frac{1}{1-u_1}\int_{u_1}^1{du_2}\left(1+u_2\right) \end{eqnarray}

In [14]:
def break_stick_exp(n)
N = 10000000
lmax_tot = 0.
for i in range(0, N):
    u1 = np.random.uniform() #0., 1.
    l1 = u1
    l2 = 1.0 - u1
    l = [l1, l2]
    lmax_tot += max(l)
    
    
print(lmax_tot/N)


0.7499946183666184

In [29]:
N = 10000000
lmax_tot = 0.
for i in range(0, N):
    u1 = np.random.uniform() 
    u2 = np.random.uniform()
    l1 = min([u1,u2])
    l3 = 1. - max([u1,u2])
    l2 = 1. - l3 - l1
    l = [l1, l2, l3]
    lmax_tot += max(l)
    
    
print(lmax_tot/N)


0.6110801070519539

In [ ]:
import dis
dis.disco(func.__code__)

In [ ]:
def harmonic_n(n):
    sm = 0 
    for i in range(n):
        sm += 1/(i+1)
    return sm

In [ ]:
print(harmonic_n(5)/5)