Random Seed Usage

when we you use random.seed to get a random number,for example if we have range of numbers between 300 and 600(Range(300,600))and we write random.seed(50) and it gives us a certain value 492, what does it mean and how is a seed correlated to a particular number ?
For example

>>> aa_milne_arr = ['pooh', 'rabbit', 'piglet', 'Christopher']
>>> np.random.choice(aa_milne_arr, 5, p=[0.5, 0.1, 0.1, 0.3])
array(['pooh', 'pooh', 'pooh', 'Christopher', 'piglet'],
      dtype='|S11'

what is the point of using probability above how does it influence the result ?

I’m not sure of the context within this specific exercise, but using the probability determines the probability that each input list element will appear in the output list.

Let’s illustrate by making a 1000 element output list:

import numpy as np

aa_milne_arr = ['pooh', 'rabbit', 'piglet', 'Christopher']
lst = np.random.choice(aa_milne_arr, 1000, p=[0.5, 0.1, 0.1, 0.3])
lst = list(lst)    # change the np array to a conventional list ...
for name in ['pooh', 'rabbit', 'piglet', 'Christopher']:
    print(name, lst.count(name))    #... so that we can use lst.count()

Output (3 runs):

pooh 525
rabbit 83
piglet 98
Christopher 294

pooh 502
rabbit 96
piglet 101
Christopher 301

pooh 518
rabbit 87
piglet 107
Christopher 288

2 Likes

Thank you for your assistance

1 Like

Patrik can you help with another problem it is in the forums