How to generate random number using business rule?

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2018 10:49 AM
Hi Team,
How to generate random number using business rule?
please help me.
Labels:
- Labels:
-
Scripting and Coding
2 REPLIES 2

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2018 11:00 AM
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;
}
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2018 11:19 AM
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