Python Forum
random.choices and random.sample
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
random.choices and random.sample
#6
21 appears twice in the population. There are two elements in the population that just happen to have the same value. random.choices() does not eliminate duplicates, it prevents selecting the same element more than once.

If you want to eliminate duplicates in the population you can use set()
azizrasul likes this post
Reply


Messages In This Thread
random.choices and random.sample - by azizrasul - Sep-16-2022, 05:50 PM
RE: random.choices and random.sample - by menator01 - Sep-16-2022, 06:05 PM
RE: random.choices and random.sample - by azizrasul - Sep-16-2022, 08:06 PM
RE: random.choices and random.sample - by deanhystad - Sep-16-2022, 08:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Frog Puzzle Random To Custom MoreMoney 4 649 Mar-26-2024, 08:38 AM
Last Post: MoreMoney
  Python logging RotatingFileHandler writes to random file after the first log rotation rawatg 0 499 Feb-15-2024, 11:15 AM
Last Post: rawatg
  Create Choices from .ods file columns cspower 3 750 Dec-28-2023, 09:59 PM
Last Post: deanhystad
  random numbers, randint janeik 2 645 Nov-27-2023, 05:17 PM
Last Post: janeik
  Sample random, unique string pairs from a list without repetitions walterwhite 1 550 Nov-19-2023, 10:07 PM
Last Post: deanhystad
  Unexpected output while using random.randint with def terickson2367 1 599 Oct-24-2023, 05:56 AM
Last Post: buran
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,549 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  List of random numbers astral_travel 17 2,900 Dec-02-2022, 10:37 PM
Last Post: deanhystad
  [split] why can't i create a list of numbers (ints) with random.randrange() astral_travel 7 1,667 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
  random methods Skaperen 16 3,146 Sep-28-2022, 10:44 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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