Write a program to display random number between 0 and 1?
Answers
Answered by
13
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());
}
}
- 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.
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
0
double r2()
{
return((rand() % 10000) / 10000.0);
}
int SA()
{
double u;
u = r2();
}
Similar questions