ALine Posted July 25, 2018 Share Posted July 25, 2018 (edited) Ok, so I was making a simple python program that mimics simple evolutionary processes. When I run it multiple times I keep getting different results and I have no idea what is happening. Please help. BasicEvolutionProgram.txt Edited July 25, 2018 by ALine Link to comment Share on other sites More sharing options...
Sensei Posted July 25, 2018 Share Posted July 25, 2018 (edited) Like we can read in Python documentation: https://docs.python.org/3/library/random.html random.seed( value ) initializes random number generator. But if it's not present in code, current time is used, but time is changing all the time.. Different seed, different results from random.randInt().. So, if you want to have each time the same results, use random.seed( 0 ); at the beginning of script. It's reverse from C/C++ implementation of random number generator, in which you must execute srand( time() ); manually if you don't want to have exactly the same results. Edited July 25, 2018 by Sensei 1 Link to comment Share on other sites More sharing options...
ALine Posted July 25, 2018 Author Share Posted July 25, 2018 Yep, you right. I get the same results each time now. Thank's Senpai. Link to comment Share on other sites More sharing options...
Sensei Posted July 27, 2018 Share Posted July 27, 2018 On 25.07.2018 at 6:53 PM, ALine said: Yep, you right. I get the same results each time now. Thank's Senpai. I am glad to help you. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now