Correct way of using random number generator with multiple m files
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Tan Biru
am 4 Okt. 2014
Kommentiert: Tan Biru
am 5 Okt. 2014
Dear MATLAB community,
I am using random functions like randi and rand in two functions in two different m files. These two m files with the random function is called from a main script. I would like to use random number generator rng to seed the random function. Do I use the rng at the main script or do I use it separately on the m files, which is the more proper way?
Thank you.
Regards,
Tan Biru
0 Kommentare
Akzeptierte Antwort
the cyclist
am 4 Okt. 2014
It depends on the reason you are setting the seed.
Do you want the two functions to be using the same set of pseudorandom numbers? Then set the seed in both function files.
Or do you want the two functions to be using different pseudorandom numbers? Then set the seed in the main function.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Random Number Generation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!