Play Games

Search This Blog

Tuesday, March 17, 2020

How to display random number in visualforce page

Apex Class: OneDigitRandomNumberController
public class OneDigitRandomNumberController {
    public Integer iRandomNumber {get;set;}
    public void generateOneDigitRandomNumber() {
        iRandomNumber = Integer.valueof((Math.random() * 10));
        System.debug('One Digit Random Number  is'+iRandomNumber);
    }
}

Visualforce Page:OneDigitRandomNumber
<apex:page controller="OneDigitRandomNumberController" action="{!generateOneDigitRandomNumber}">
<apex:form >
<b> One Digit Random Number: </b> {!iRandomNumber}<br/>
<apex:commandButton action="{!generateOneDigitRandomNumber}" value="Refresh"/>
</apex:form>
</apex:page>
Output:

No comments:

Post a Comment