0
num= 100
obs=[]
np.random.seed(1)

for i in range(num):
  
  N=[]
  CF3_1=[]
  CF3_2=[]
  i=2

  salvage= np.random.triangular(salvage_min, salvage_mode, salvage_max)
  inv= np.random.uniform(inv_min, inv_max)

  for y in range(0,5):
    
    gt= 14.747101 + 11.664259 * np.random.beta(0.645868, 0.920589)
    print(gt)
    

I am trying to get gt to start with np.random.seed(1) but it seems like gt does not start with seed 1.

np.random.seed(1)
gt= 14.747101 + 11.664259 * np.random.beta(0.645868, 0.920589)
print(gt)

produces a result of:

17.889105013452703
14.747134750650536
19.474766202077234
16.967191836499126
18.465043981244925
18.03420202040634
15.794033025059752

while the result of my code is:

14.747134750650536
19.474766202077234
16.967191836499126
18.465043981244925
18.03420202040634

Notice that the result of my code is the exact same, only that it skipped 17.889105013452703.

3
  • 1
    not sure what the issue is, as I ran your code without the salvage part and got 17... , and when I ran the couple lines and got the same value. explicitly write the code for the two cases which give the two different results. I suspect it is a problem with the code, as opposed to the seed. Commented Nov 2, 2022 at 23:13
  • I think it's the salvage and inv that's affecting the random seed. I had to do a scenario without salvage value, and so I didn't include that salvage and inv lines, and got the same value. Any idea on why random seed would affect the next line or how I could get "gt" to start at 17? Commented Nov 2, 2022 at 23:21
  • quite obvious when @craigb outlined the issue :) Commented Nov 3, 2022 at 0:40

1 Answer 1

1

This is to be expected. np.random.triangular and np.random.uniform each consume a random double (64 bits), while np.random.beta consumes two doubles; see source.

So after you reset the seed, calling np.random.triangular and np.random.uniform once each will consume two doubles, which means the values returned by successive np.random.beta calls will be one value behind what it returns without those two prior calls.

If you want your gt sequence to start with np.random.seed(1) then you should call np.random.seed(1) after you've called the other functions that consume random values (ie, before the inner for loop).

If you want np.random.triangular and np.random.uniform to generate random values (ie, not be repeatable due to np.random.seed(1)) you should create a separate random generator to use with them.

Sign up to request clarification or add additional context in comments.

1 Comment

can't believe I did not see this when I removed those statements. thumbsup.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.