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

  • Home
  • SEARCH
  • 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 1035033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:29:05+00:00 2026-05-16T14:29:05+00:00

How to generate a random (but unique and sorted) list of a fixed given

  • 0

How to generate a random (but unique and sorted) list of a fixed given length out of numbers of a given range in Python?

Something like that:

>>> list_length = 4
>>> values_range = [1, 30]
>>> random_list(list_length, values_range)

[1, 6, 17, 29]

>>> random_list(list_length, values_range)

[5, 6, 22, 24]

>>> random_list(3, [0, 11])

[0, 7, 10]
  • 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-16T14:29:06+00:00Added an answer on May 16, 2026 at 2:29 pm

    A random sample like this returns list of unique items of sequence. Don’t confuse this with random integers in the range.

    >>> import random
    >>> random.sample(range(30), 4)
    [3, 1, 21, 19]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to generate unique random numbers between 0 and 1000 that never repeat
I need to generate random UNIQUE numbers within a range, how can I do
i want to generate a sequence of unique random numbers in the range of
How to generate random numbers using assembly code in the range 1--4 ?
Possible Duplicates: Unique (non-repeating) random numbers in O(1)? How do you efficiently generate a
Im trying to generate n unique random numbers between 1 and max I tried
I've got a project where we'll need to generate a lot of fixed-length random
What is an efficient way of generating N unique numbers within a given range
I need to generate 8 random integers, but they need to be unique, aka
I want to generate unique and random numbers or IDs which I can use

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.