Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2010
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    making a random character generator

    Hello, I am making a little program that randomly generates one random character, either 'a', 'b', or 'c'.
    I know how to make a random number generator, but the character generator is giving me some trouble.

    Can anyone help me out?

    I found this little line, but it doesn't really do what I want it to do.
    Code:
    String AI_class = Long.toString(Math.abs(a.nextLong()), 36);
    Any help would be great,

    Bananas.

  • #2
    New Coder
    Join Date
    Feb 2011
    Posts
    69
    Thanks
    0
    Thanked 7 Times in 7 Posts
    One way to do it is to

    1) put all you valid chars in an array

    2) generate a random number between 0 and the array length-1

    3) get the array element value at the index of the random number in 2)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •