[Go to site: main page, start]

0% found this document useful (0 votes)
5 views3 pages

Using Math.random in Java

The document explains how to use the Math.random function in programming to generate random integers. It provides formulas for generating random integers within a specified range, including inclusive and exclusive boundaries. Examples include generating a random integer between A and B, as well as from 0 to 10.

Uploaded by

mncedisimalgas
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Using Math.random in Java

The document explains how to use the Math.random function in programming to generate random integers. It provides formulas for generating random integers within a specified range, including inclusive and exclusive boundaries. Examples include generating a random integer between A and B, as well as from 0 to 10.

Uploaded by

mncedisimalgas
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

🎲

How to Math Class:


[Link]

How to Math Class: [Link] 1


How to Math Class: [Link] 2
//the general formula for math random goes
//int x = (int)([Link]()*differenceInSet(+1 if inclusive))+StartofSet

//to produce one random integer between A and B(inclusive)


int randNum = (int) ([Link]() * (B-A+1)) + A;

//to produce a random integer from 0(including) to 10(excluding)


//since [Link] produces numbers between 0(including) and 1(exluding) th
int randNum2 = (int) [Link]() * 10;

//to produce a random integer from 0(incl) to 10(incl)


int randNum3 = (int) ([Link]()*10+1);

How to Math Class: [Link] 3

You might also like