Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By ContoNick

Thread: How do I create a code that generates random text?

  1. #1
    Join Date
    Feb 2012
    Posts
    4
    Rep Power
    0

    Default How do I create a code that generates random text?

    How do I create a code that generates random text?

    I know how to create a random int generator for colors, but not for text.

    I want to display three different phrases randomly upon my mouse leaving the canvas. ex. public void onMouseExit(Location point)

    I'm using Blue J/objectdraw by the way.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: How do I create a code that generates random text?

    You could put the phrases into an array, then use a randomly chosen value as the index into that array.

  3. #3
    Join Date
    Feb 2012
    Posts
    4
    Rep Power
    0

    Default Re: How do I create a code that generates random text?

    I'm sorry I don't exactly understand how to do that... Example would be nice?

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default Re: How do I create a code that generates random text?

    Quote Originally Posted by Maya Berkowitz View Post
    I'm sorry I don't exactly understand how to do that... Example would be nice?
    I'm sure it would, but, assuming you already know how to copy/paste, you wouldn't learn anything new that way.

    Which part are you having trouble with? This?
    Quote Originally Posted by pbrockway2 View Post
    You could put the phrases into an array
    Or this?
    Quote Originally Posted by pbrockway2 View Post
    then use a randomly chosen value
    Or this?
    Quote Originally Posted by pbrockway2 View Post
    as the index into that array.
    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    ContoNick is offline Member
    Join Date
    Dec 2011
    Location
    Croatia,Zagreb
    Posts
    24
    Rep Power
    0

    Default Re: How do I create a code that generates random text?

    example:

    Java Code:
    // Moderator edit: full solution removed
    something like this ?

    i wonder how u even made some project doing some stuff and u dont know how to get random item from array :O -.-'
    Last edited by DarrylBurke; 02-07-2012 at 10:41 PM. Reason: Removed spoonfeeding

  6. #6
    rokit boy is offline Member
    Join Date
    Feb 2012
    Posts
    35
    Rep Power
    0

    Default Re: How do I create a code that generates random text?

    Java Code:
    import java.util.Random;
    
    public class Main {
        int rand = new Random().nextInt(HOW MUCH YOU WANT THE LARGEST NUMBER TO BE) + 1;
        System.out.print(ran);
    }
    SORRY THAT'S AN INT, I DIDN'T READ THE POST.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default Re: How do I create a code that generates random text?

    ContoNick, please don't spoonfeed. That deprives the questioner of the opportunity to learn. I've edited your post and removed the full solution.

    rokit boy, we still don't know what part the OP is stuck on. I've broken the problem into three parts, we should wait for a reply so that we don't waste effort and forum space suggesting what is already known.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  8. #8
    ContoNick is offline Member
    Join Date
    Dec 2011
    Location
    Croatia,Zagreb
    Posts
    24
    Rep Power
    0

    Default Re: How do I create a code that generates random text?

    @DarrylBurke
    sorry my mistake :/ , i wont give them finished solution's anymore
    DarrylBurke likes this.

Similar Threads

  1. My program generates new errors
    By BenH in forum New To Java
    Replies: 8
    Last Post: 01-31-2012, 06:21 AM
  2. HELP! not sure how to create random Array
    By vanilla88 in forum New To Java
    Replies: 3
    Last Post: 09-30-2011, 10:10 AM
  3. Hello? How to Create Random access???
    By Miyaki in forum New To Java
    Replies: 1
    Last Post: 03-05-2009, 06:37 AM
  4. Random access to text file
    By lunarbof in forum New To Java
    Replies: 1
    Last Post: 11-05-2008, 08:53 PM
  5. Generates random maths questions
    By cachi in forum New To Java
    Replies: 4
    Last Post: 08-01-2007, 04:48 AM

Posting Permissions

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