• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

random letters problem

 
mark maccuish
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey everyone,this might be a hard subject, but ill ask anyways.
I created this guessing game, 1 random number is randomly created and i get 5 chances to guess it correctly, if i do so in 5, i get 1 "bull" (point) if i dont, the computer does, and it keeps track of points. This is fairly easy and i did it no problem. HOWEVER, part B) of the program is killing me!!!
i have to now randomly generate 3 random letters (A-E) [and they cannot be the same] and guess 1 letter at a time till i get all 3. i.e. ABE is randomly created, if i guess C and hit "guess" button, i get 1 "miss" if i guess A i get a "bull" and score a point. Althought i thought this would be easy, i am having SOOOOOOO much trouble, can anyone PLEASE help me out? what would be the easiest way of approaching it? im really stuck on the validation part, i.e. after i submit the letter, how do i validate it against the "secret" random 3 letter'd word already created to see if theres a letter in it ? please help i am in dire trouble.
[removed the "HELP" from the subject, as it's somewhat redundant when asking questions in a forum - Ilja]
[ April 30, 2004: Message edited by: Ilja Preuss ]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33671
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark,
I'm not sure what this has to do with performance, but remember letters are ordered in ASCII. So you can use the same idea as with the numbers and add the letter to 'A'. For example, 'A' + 2 = 'C'
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Java in General (intermediate)...
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I heard you have to use A through E with no duplicates. So BDE would be good, but ABB would not.
A common approach is to "shuffle" the list. It works well for shuffling cards or generating lottery numbers. To get three random letters, try something like this:

Try this and see what kind of scrambles you get. You might shuffle more than once if you don't trust one round of swapping.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic