Jump to content

Recommended Posts

Posted (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 by ALine
Posted (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 by Sensei
Posted
On 25.07.2018 at 6:53 PM, ALine said:

Yep, you right. I get the same results each time now. Thank's Senpai. :D

I am glad to help you.

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.