Math Class

Generate random numbers using Math.random

Want to learn quickly?
Try one of the many quizzes. More than Java 400 questions with detailed answers.

Add Comment

  • Please tell : methods to create array, add elements into it, shuffle contents of
    array, search for an element in the array.

  • Is it possible to generate a number that when it generates another that is NOT the same one.
    For example to avoid an output like this;

    1
    4
    2
    1
    3

    Is there a way to avoid the 1 appearing twice?

    • Use an if statement. If you get a number previously outputed then simply draw another number. Becareful that you have enough options or you will get an error/non-ending program.

  • I am a total newbie what programming

    how should i start that????

    thank you

    variables: double a, b, c;
    int d, e, f, g;

    a <— random number in the interval [0; 1[

    b <— random number in the interval [0; 3.141592[

    c <— random number in the interval [4.08; 15[

    d <— whole random number in the interval [23, 42[

    e <— whole random number in the interval [6, 49[

    f <— whole random number in the interval [0, 36[

    g <— whole random number in the interval [1; 100[

    Output: Values ??of variables a to g?

Sponsors

Facebook Fans