python - random.shuffle Randomness -
python - random.shuffle Randomness -
i trying write genetic algorithm homework solve travelling salesman problem.
one of mutation functions i'm trying utilize random.shuffle on tour.
when read documentation random.shuffle, see:
shuffle(self, x, random=none, int=<type 'int'>) method of random.random instance x, random=random.random -> shuffle list x in place; homecoming none. optional arg random 0-argument function returning random float in [0.0, 1.0); default, standard random.random. could please explain function of "random" parameter in function? have read this question, doesn't reply question.
i utilize function if can somehow command how random shuffling (if makes sense)
the random argument used specifying (another) random number generator. it's function expected homecoming uniform random numbers in range 0<=x<1
if same number returned twice random number generator, shuffle same. example,
def mynonrandom(): homecoming 0.1 q [1, 2, 3, 4] random.shuffle(q, mynonrandom) q [2, 3, 4, 1] random.shuffle(q, mynonrandom) q [3, 4, 1, 2] note in particular case got shift of -1 each time. random input may depend on implementation of random.shuffle.
for genetic algorithm want able have variable sized randomness of shuffle. not done random.shuffle. need define illustration changes (pairs distance n swapping example) , randomize (with parameters you'll define) how many of operations perform each new set of genes.
python random optional-parameters shuffle
Comments
Post a Comment