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
Find more posts tagged with
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..
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,
Renan
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,
Renan
Hi Shyam
Please check the following link to get a better understanding of the srand function: https://cplusplus.com/reference/cstdlib/srand/
Thanks,
Jerrin Job