I'm really confused by a lot of the answers on here pertaining to creating same set of random numbers between function calls.
Some people are saying you will get non-repeating numbers if you seed the random function, other the exact opposite. Can someone please show me how this is done in VB.Net?
Goal:
• I want to have seed: a
• I call the rand function within main: rand(a)
• Given n number of function calls to rand, rand(a) gives set of random numbers A,
• Run ends
• I run main again and I expect to get the same set of random numbers A
Here's some thoughts:
Private Function Generate_Random_Number(Byval Lower as integer, Byval Upper as integer, Byval seed as integer)
Dim Random_Value as Integer
randomize(seed)
random_value = rand.next(lower, upper + 1)
Return random value
End Function
Private Sub Main()
Seed = 100
For i = 0 to 1 'run this function for two times
Get_Random_Numbers(Seed)
Next i
End Sub
Private Sub Get_Random_Numbers(Seed)
Dim x, y, w, z as integer
x = Generate_Random_Number(0,1, seed)
y = Generate_Random_Number(1,2, seed)
w = Generate_Random_Number(2,3, seed)
z = Generate_Random_Number(3,4, seed)
End Sub
Suppose the first function call to Get_Random_Numbers give me {x = 0, y = 1, w = 2, z = 3}, for whatever reason the next call to Get_random numbers give me {x = 1, y = 2, w = 3, z= 4} which is completely different from the first time I called this function!
But I'm using the same seed?
Can someone tell me what I'm doing wrong?
Thank you