• 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
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Adding random numbers to my list

 
Ranch Hand
Posts: 264
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: 65474
249
  • 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.
 
Proudly marching to the beat of a different kettle of fish... while reading this tiny ad
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!