CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2003
    Posts
    51

    java random function

    Hello guys,
    I want to know how i can generate a random value in java, and which package will be included,
    for example i want to add 4 random values

    int i=0;
    i+=function();

    and second one how i can convert a string into capital latters in java.
    thanks in advance.

    PUNJABIAN263
    PUNJABIAN263

  2. #2
    Join Date
    Apr 2003
    Location
    Cheltenham, UK
    Posts
    500
    Live as if you were to die tomorrow. Learn as if you were to live forever.

  3. #3
    Join Date
    Oct 2003
    Posts
    51

    thanks

    Hello ArchAngle,
    Thanks for this help, I will check it.

    PUNJABIAN263

    ***GOD HELPS THOSE WHO HELP THEMSELVES***
    PUNJABIAN263

  4. #4
    Join Date
    Jun 2001
    Location
    Eugene, Oregon
    Posts
    51
    import java.util.Random;

    Random randGen = new Random();

    What you do next depends on the type of random numbers you wish to generate; two possibilities are:

    int myInt;
    myInt = randGen.nextInt();

    float myFloat;
    myFloat = randGen.nextFloat();

    ----------------------------------------------------

    String myString = "Hi punjabian263!";

    String myUpString = myString.toUpperCase();

  5. #5
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104
    a fast and dirty approach:

    Math.random() generates a number between 0.000 and 1.000

    so for a random number between 0 and 1000:

    int randomInt = Math.random() * 1000

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured