Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7194901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:28:09+00:00 2026-05-28T20:28:09+00:00

I am trying to write a genetic algorithm for homework to solve the travelling

  • 0

I am trying to write a genetic algorithm for homework to solve the travelling salesman problem.

One of the mutation functions that I’m trying is to use random.shuffle on the tour.

When I read the documentation for random.shuffle, I see:

shuffle(self, x, random=None, int=<type 'int'>) method of random.Random instance
x, random=random.random -> shuffle list x in place; return None.

Optional arg random is a 0-argument function returning a random
float in [0.0, 1.0); by default, the standard random.random.

Could someone please explain the function of the “random” parameter in this function?
I have read this question, but it doesn’t answer my question.

I would especially like to use this function if I can somehow control how random the shuffling would be (if that makes any sense)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:28:10+00:00Added an answer on May 28, 2026 at 8:28 pm

    The random argument is used for specifying (another) random number generator. it’s a function expected to return uniform random numbers in the range 0<=x<1

    If the same number is returned twice from the random number generator, the shuffle will be the same. For example,

    def mynonrandom():
     return 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 that in this particular case I got a shift of -1 each time. Exactly what you get for a random input may depend on the implementation of random.shuffle.

    For a genetic algorithm you want to be able to have variable sized randomness of the shuffle. That is not done with random.shuffle. You probably need to define some example changes (pairs with distance N swapping for example) and then randomize (with some parameters you’ll define) how many of those operations you perform for each new set of genes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to write a couple of functions that will encrypt or decrypt a file
I'm trying to write some generic http response handler functions that sometimes open UIAlertViews.
I am trying to write a C++ program for the canonical genetic algorithm ,
I am trying to write a generic Parse method that converts and returns a
Trying to write a PowerShell cmdlet that will mute the sound at start, unless
I'm trying to write a generic method that can be used to deserialize xml
I'm trying to write a generic interpolate method that works on any type that
I am trying to write a generic one-size-fits-most repository pattern template class for an
I am trying to write a generic Heap Sort algorithm. I get the following
Im trying to write a generic base class that will allow sub classes to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.