Play Games

Search This Blog

Monday, October 31, 2016

Generate Random Number in Salesforce

Using Math.Random() we can generate random Number
Example :
Apex Class:
public class RandomNumberController {
    public Double randomNumber {get;set;}
    public RandomNumberController() {
        randomNumber = Math.random();  
    }
}
Visualforce Page:
<apex:page controller="RandomNumberController">
  <B>Random Number is:</B>{!randomNumber}
</apex:page>
Output : Everytime you run the vf page,you get different numbers as output as shown in the images below.



No comments:

Post a Comment