Python Forum
Lottery generator (beginner)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lottery generator (beginner)
#4
Shouldn't random.sample be more suitable for task at hand?

>>> import random
>>> help(random.sample)
Help on method sample in module random:

sample(population, k) method of random.Random instance
    Chooses k unique random elements from a population sequence or set.
    
    Returns a new list containing elements from the population while
    leaving the original population unchanged.  The resulting list is
    in selection order so that all sub-slices will also be valid random
    samples.  This allows raffle winners (the sample) to be partitioned
    into grand prize and second place winners (the subslices).
    
    Members of the population need not be hashable or unique.  If the
    population contains repeats, then each occurrence is a possible
    selection in the sample.
    
    To choose a sample in a range of integers, use range as an argument.
    This is especially fast and space efficient for sampling from a
    large population:   sample(range(10000000), 60)
(END)
So you just can write:

>>> for i in range(10):
...     print(random.sample(range(1, 100), 10))
...
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
Lottery generator (beginner) - by Hullari - Jul-03-2019, 02:59 PM
RE: Lottery generator (beginner) - by ichabod801 - Jul-03-2019, 03:20 PM
RE: Lottery generator (beginner) - by Hullari - Jul-03-2019, 03:59 PM
RE: Lottery generator (beginner) - by perfringo - Jul-03-2019, 04:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help with defining messages and player guesses in a lottery Kanashi 3 2,336 Nov-23-2019, 10:14 AM
Last Post: ThomasL
  [split] Lottery System on my mobile website sibt007 1 2,458 Sep-27-2018, 12:56 AM
Last Post: micseydel
  Lottery System on my mobile website nooxm123 1 2,624 Feb-06-2018, 10:55 AM
Last Post: j.crater
  receive from a generator, send to a generator Skaperen 9 5,529 Feb-05-2018, 06:26 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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