Python Forum
Generate a list of numbers within a list of arbitrary numbers
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Generate a list of numbers within a list of arbitrary numbers
#2
I don't understand what the problem with using random.sample() is
from random import sample

population = (23, 2, 49, 100, 101)
my_sample = sample(population, 3)
print(my_sample)
Output:
[101, 100, 49] >>>
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: Generate a list of numbers within a list of arbitrary numbers - by buran - Nov-07-2018, 12:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Strange behavior list of list mmhmjanssen 2 194 May-01-2024, 07:16 AM
Last Post: Gribouillis
  How do I calculate a ratio from 2 numbers and return an equivalent list of about 1000 Pleiades 8 15,775 Jan-05-2024, 08:30 PM
Last Post: sgrey
  random numbers, randint janeik 2 585 Nov-27-2023, 05:17 PM
Last Post: janeik
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 1,230 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  Why doesn't calling a parent constructor work with arbitrary keyword arguments? PurposefulCoder 4 977 Jun-24-2023, 02:14 PM
Last Post: deanhystad
  Advancing Page Numbers knight2000 4 1,019 May-24-2023, 09:14 AM
Last Post: knight2000
  Delete strings from a list to create a new only number list Dvdscot 8 1,584 May-01-2023, 09:06 PM
Last Post: deanhystad
  Pulling Specifics Words/Numbers from String bigpapa 2 787 May-01-2023, 07:22 PM
Last Post: bigpapa
  How do I check if the first X characters of a string are numbers? FirstBornAlbratross 6 1,580 Apr-12-2023, 10:39 AM
Last Post: jefsummers
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,285 Apr-05-2023, 07:36 PM
Last Post: Frankduc

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020