Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Adding random numbers to my list  RSS feed

 
Ranch Hand
Posts: 177
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for a laugh im writing a random lottery number generator


   
but what i have noticed is that every few draws im only getting 5 numbers. I have gone over things a few times and guess its something to do with when the same number is drawn
im not sure about these lines:



can somebody please give me some advice on how to handle something like this.

this seems to work, no duplicate numbers, only 5, tell me what you think



dont know why i was adding after changing the random number again

is there a more efficient way of doing this?







Why cant i reply to my thread? i can only edit the original.

Irish lottery has a few draws with different number schemes, casue the Irish do things differently lol!

here is the entire program, seems to work well, though sometimes the exit isnt ending the menu loop. but i will look at it again



Please Campbell, tell me something to write!!!
 
Marshal
Posts: 64166
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought the numbered balls ran 1...49inclusive.
Are you getting any numbers duplicated? Remember that randomness entails duplicates If you choose two random numbers there is a chance that you will get a duplication. Your test for duplicates doesn't guarantee six unique numbers; it is quite possible for the same number to come up thrice. In which case you won't get six distinct numbers.
 
Nothing? Or something? Like this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!