Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Switch Case

 
Mathew Mintalm
Ranch Hand
Posts: 103
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, would be great if someone can help me.

So I'll try to describe my problem.

So I have code with switch case, something like:



I made some kind of lottery, which selects a random option from this switch case.

I now Im wondering how to disable choosing the same option once again.

For example, in my last lottery choosen option was case1, so now i would like to disable this case in next lottery.

Please help me, thanks in advice.
 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way would be to remember what was your last result from random, and if it matches your newly picked number, just keep picking them till they don't match. Better solutions would include some kind of a Collection, ie. a Set. Once you draw your number you remove it, next time you pick from what is left in your bag.
 
Mathew Mintalm
Ranch Hand
Posts: 103
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I have to think about how to do it.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that the key to Martin's suggestion is about how you select the number in the first place -- not in "disabling" cases.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48976
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
marc weber wrote:-- not in "disabling" cases.
I haven't looked at your problem in any sort of detail, but I suspect it will be better with the switch block replaced by something totally different.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic