How to generate random number using business rule?

Sudesh Ram
Kilo Contributor

Hi Team,

 How to generate random number using business rule?

please help me.

2 REPLIES 2

Rick Marsha
Giga Expert

Hi Sudesh,

Here's a function that creates a random, 12-character password, but could be used to create any random characters.. just adjust the charset as needed. You can use parseInt() on the result to convert the string to a integer type.

var tmpPwd = credGenNow();

function credGenNow() {
	var newOpenPwd = '';
	var charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!%@#';

	for (var i = 0; i < 12; i++) {
		newOpenPwd += charSet.charAt(Math.floor(Math.random() * charSet.length));

	}

	return newOpenPwd;

}

ARG645
Tera Guru

Simple and Specific, 

This one generates random numbers only, you can specify the outbound limit in line 1. 

Example to generate random numbers from 0-9

var n= 10; // Outbound Limit
var x = Math.floor(Math.random() * n); //Generates random number from 0-n
gs.print(x);//Just a print statement, you dont have to use it though