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 7604155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:50:16+00:00 2026-05-30T23:50:16+00:00

So I have a list of 4 strings in Python and I want to

  • 0

So I have a list of 4 strings in Python and I want to return that list, but randomized and only up to a specific number (the variable ‘players’ in the code below). I CANNOT use the shuffle function, but trust me if I could, I would.

Here is the code I have so far:

players = raw_input('How many players? ')
players = int(players)
Roles = ["Role1", "Role2", "Role3", "Role4"]
print Roles[:players]

I need to somehow use the random.seed() function to randomize the list. I’m really confused by this, because I thought you could only use random.seed() with numbers, not a list of strings. If anyone could help with this I would really appreciate it.

  • 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-30T23:50:18+00:00Added an answer on May 30, 2026 at 11:50 pm

    While random.shuffle (or random.sample) is The Python Way, consider using an existing well-known approach if it is truly not an option. The code below is an implementation of the Fisher-Yates Shuffle (it is adapted from the Sattolo’s variant code found on that page):

    from random import randrange
    
    def shuffle(items):  # mutates input list
        i = len(items)
        while i > 1:
            j = randrange(i)  # 0 <= j <= i
            items[j], items[i] = items[i], items[j]
            i = i - 1
        return
    

    Another approach that is sometimes seen floating about is to zip a list with a sequence of random numbers, sort based on the random numbers, and then extract the original values.

    from random import random
    
    def shuffle(items):  # returns new list
        return [t[1] for t in
                sorted((random(), i) for i in items)]
    

    In any case, random.seed merely sets the seed for the PRNG (Pseudo-random number generator) used. That is, random.seed will affect future random numbers generated (and functions which utilize them), but will not itself “get” a random value or “shuffle” or “randomize” anything. (It is usually fine if it is not called, as there is a suitable “default seed” set, but sometimes it’s nice – e.g. for repeatability in tests or Solitaire games – to set a particular seed.)

    For instance, try this: (If using Python 2.x, remove the parenthesis from the print):

    from random import seed, random
    
    # should all be the same value, whatever that is.
    seed(1)
    print(random())
    seed(1)
    print(random())
    seed(1)
    print(random())
    
    # should be two different values (and different from above)
    print(random())
    print(random())
    
    # should be same as first three values
    seed(1)
    print(random())
    

    The key to understand is a PSEUDO RANDOM source (PRNG) takes the CURRENT internal state – which can be set with a “seed”, although a modern PRNG has a much larger internal state – and uses that to generate a random value and the NEXT internal state. A TRUE RANDOM source (e.g. specialty hardware that samples static noise) does not have the concept of a “seed”.

    Happy coding.

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

Sidebar

Related Questions

I have a List of strings that is regenerated every 5 seconds. I want
Using bash, I have a list of strings that I want to use to
I have sorted list of strings that I move between php and java. to
Kind of a weird question, but. I need to have a list of strings
I have a list of 400 strings that all end in _GONOGO or _ALLOC.
I have huge list (200000) of strings (multi word). I want to group these
I have two strings in python that I have converted to lists: Seq1 =
I have a list of lists of three strings in Python, e.g., m =
I'm new to python, and have a list of longs which I want to
Hi I have list of strings in python [ 0, 1, 2] and I

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.