You are on page 1of 4

>>> import random

>>> import random as R

>>> dir(R)
['BPF', 'LOG4', 'NV_MAGICCONST', 'RECIP_BPF', 'Random', 'SG_MAGICCONST',
'SystemRandom', 'TWOPI', 'WichmannHill', '_BuiltinMethodType', '_MethodType',
'__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__',
'_acos', '_ceil', '_cos', '_e', '_exp', '_hashlib', '_hexlify', '_inst',
'_log', '_pi', '_random', '_sin', '_sqrt', '_test', '_test_generator',
'_urandom', '_warn', 'betavariate', 'choice', 'division', 'expovariate',
'gammavariate',
'gauss',
'getrandbits',
'getstate',
'jumpahead',
'lognormvariate',
'normalvariate',
'paretovariate',
'randint',
'random',
'randrange',
'sample',
'seed',
'setstate',
'shuffle',
'triangular',
'uniform', 'vonmisesvariate', 'weibullvariate']

R.random()
R.suffle(L)

>>> x = R.random()
>>> x
0.42108266710640985
>>> x = R.random()*10
>>> x
8.739661030083589

R.randint(n, m)

>>>
>>>
9
>>>
>>>
1
>>>

x = int(R.random()*10)
x
x = R.randint(1, 9)
x

>>> L = [[1,2],[3,4]]
>>> L[0][1]
2
>>> M = dict()
>>> M[0,0]=1
>>> M[0,1]=2
>>> M[1,0]=3
>>> M[1,1]=4
>>> M
{(0, 1): 2, (1, 0): 3, (0, 0): 1, (1, 1): 4}

>>> L = []
>>> for i in range(4): L.append([0 for j in range(4)])
...
>>> L
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
>>>

You might also like