function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
pg7pg7 

hope to get random number

hi

 

 

i'm developing a calculation application.

 

i hope to get  a random number

and display it in a visualforce page by using an apex controller or some class.

 

 

could anybody tell me a code to get a random number?

Best Answer chosen by Admin (Salesforce Developers) 
prageethprageeth

Use this

 

public double getRandomNumber() {

return Math.random();

}

 

this returns a random value between 0 and 1.

If you need a larger value you can multiply it by a larger number. 

All Answers

prageethprageeth

Use this

 

public double getRandomNumber() {

return Math.random();

}

 

this returns a random value between 0 and 1.

If you need a larger value you can multiply it by a larger number. 

This was selected as the best answer
pg7pg7

hi,prageeth

 

thank you for your reply.

this solved my problem.