This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Adding random numbers to my list  RSS feed

 
Ranch Hand
Posts: 185
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: 64495
225
  • 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.
 
Don't sweat petty things, or pet sweaty things. But cuddle this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!