Computer Science, asked by kiranshaily1, 5 hours ago

Write a program to display random number between 0 and 1?​

Answers

Answered by anindyaadhikari13
13

\textsf{\large{\underline{Solution}:}}

The given problem is solved using language - Java.

public class Main{

   public static void main(String args[]){

       System.out.println("A random number between 0 and 1 is: "+Math.random());

   }

}

\textsf{\large{\underline{Explanation}:}}

  • The Math.random() function returns a random number between 0 and 1. It returns a double type value.
  • Using this function, the problem is solved.

See attachment for output. Note that the output may be different.

\textsf{\large{\underline{Learn More}:}}

We can modify the Math.random() function to fulfill some specific tasks.

1. To generate a random number between 1 and k.

> int x = (int)(Math.random() * k) + 1;

2. To generate any random number between m and n.

> int x = (int)((Math.random() * (n - m)) + m);

Attachments:

anindyaadhikari13: Thanks for the Brainliest ^_^
Answered by anuragchandra4022k
0

double r2()

{

return((rand() % 10000) / 10000.0);

}

int SA()

{

double u;

u = r2();

}

Similar questions