def pseudorandom(n, p, random_state=None):
 import numpy as np
 p = list(p)
 cp = np.cumsum(([0] + p))
 assert np.allclose(1, cp[(-1)])
 assert (len(p) < 256)
 if (not isinstance(random_state, np.random.RandomState)):
  random_state = np.random.RandomState(random_state)
 x = random_state.random_sample(n)
 out = np.empty(n, dtype='i1')
 for (i, (low, high)) in enumerate(zip(cp[:(-1)], cp[1:])):
  out[((x >= low) & (x < high))] = i
 return out

def pseudorandom ( n , p , random_state = None ) : import numpy as np p = list ( p ) cp = np . cumsum ( ( [ 0 ] + p ) ) assert np . allclose ( 1 , cp [ ( - 1 ) ] ) assert ( len ( p ) < 256 ) if ( not isinstance ( random_state , np . random . RandomState ) ) : random_state = np . random . RandomState ( random_state ) x = random_state . random_sample ( n ) out = np . empty ( n , dtype = 'i1' ) for ( i , ( low , high ) ) in enumerate ( zip ( cp [ : ( - 1 ) ] , cp [ 1 : ] ) ) : out [ ( ( x >= low ) & ( x < high ) ) ] = i return out
pseudorandom array of integer indexes .