Python Forum
Can i prevent the random generator to generate already used numbers?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can i prevent the random generator to generate already used numbers?
#1
Hi all!

I'm new to Python and played around a bit with the random module a little as a part of my learning process.
I wanted to do i lottery game that randomly spits out 7 numbers in the range of 1 to 34 and puts them in a list.

The problem is that the random generator will generate the same number more than once. I was able to solve this by generating a new set of numbers if doubles were found. But what i would prefer to do is preventing the random generator to generate already used numbers, as it would in a real lottery game. The used numbers should be excluded from the random generator so to speak. Is this possible to do?

Thanks a lot for your help!

                for x in range(0, 7):
                        lottorad[x] = random.randint(1, 34)
Reply


Messages In This Thread
Can i prevent the random generator to generate already used numbers? - by MauserMan - Jan-05-2020, 04:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  random numbers, randint janeik 2 586 Nov-27-2023, 05:17 PM
Last Post: janeik
Question Using SQLAlchemy, prevent SQLite3 table update by multiple program instances Calab 3 786 Aug-09-2023, 05:51 PM
Last Post: Calab
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,300 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  prime numbers with iterator and generator cametan_001 8 1,937 Dec-17-2022, 02:41 PM
Last Post: cametan_001
  List of random numbers astral_travel 17 2,781 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,573 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
  Generate random id (please help!) Kjaglewicz 8 2,040 Aug-29-2022, 09:37 AM
Last Post: fracjackmac
Smile How we can prevent screen recording murad_ali 3 1,877 Jul-29-2022, 10:29 AM
Last Post: DeaD_EyE
  How to prevent python from going to new line in for loop? idknuttin 3 4,985 Feb-11-2022, 05:40 AM
Last Post: deanhystad
  Random coordinate generator speed improvement saidc 0 2,073 Aug-01-2021, 11:09 PM
Last Post: saidc

Forum Jump:

User Panel Messages

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