How to change seed for random coordinate generation in the API?
I am trying to generate random coordinates between -150.0E-6 to 150.0e-6 but when i use this function
I get random coordinates but when i repeat the simulation i get the same set of coordinates. so i am trying to change the seed of the random number generator. Hence I try this to change the seed value
Hence i tried to generate a random integer using srand function but this gives me numbers which are not random they give me one random coordinate and all other random coordinates stack on top of each other.
Please tell me how to change the seed value for the random number generator
Best Answer
-
Hi Shyam,
Here's a detailed solution to your problem regarding random numbers generation and why you should avoid the rand function : https://stackoverflow.com/questions/288739/generate-random-numbers-uniformly-over-an-entire-range
Regards,
Renan1
Answers
-
Hi Shyam
Please check the following link to get a better understanding of the srand function: https://cplusplus.com/reference/cstdlib/srand/
Thanks,
Jerrin Job0 -
Yes i wrote those lines which are commented out in green based on this (https://cplusplus.com/reference/cstdlib/srand/)
I am not trying to say i get same x y coordinates for that if i include srand in between ThisRandNuX and thisRandNuY i will get different random number.
What i am trying to ask is
Say i want to generate 10 particles, if i run the lines which are commented out (ones in green)
i will get same random number for 1st particle.. 2nd particle..3rd particle etc.
Why do i not get a different random number? Thats is what i am trying to ask.
When a new particle is about to be generated
srand(::time(NULL)) line will re-run and i expected to see a different random number for particle 2 and 3 etc..
0 -
Hi Shyam,
Here's a detailed solution to your problem regarding random numbers generation and why you should avoid the rand function : https://stackoverflow.com/questions/288739/generate-random-numbers-uniformly-over-an-entire-range
Regards,
Renan1 -
I tried the one you suggested from stack overflow everytime it gives the same pattern
positioning i will fix it but it gives the same pattern every time i want the pattern to change when i run the simulation next time
0 -
never mind please ignore it. that code works i fixed the positions..i have to give it a minute for the pattern to change
0