Number, Generate Random
Number, Generate Random
Generates a random number. When a token reaches this automated step, a numerical value within the specified range is generated each time. The decimal is rounded down to 0 according to the workflow data definition.
Configs
  • A: Set Lower Limit (e.g. “0”, “-0.5”) *#{EL}
  • B: Set Upper Limit (e.g. “10”, “0.5”) *#{EL}
  • C: Select NUMERIC DATA for Generated Number (update) *
Script (click to open)
// GraalJS Script (engine type: 2)
// (c) 2021, Questetra, Inc. (the MIT License)

//////// START "main()" ////////
main();
function main(){ 


//// == Config Retrieving / 工程コンフィグの参照 ==
const lower   = configs.get( "conf_Lower"   ) + ""; // config required
const upper   = configs.get( "conf_Upper"   ) + ""; // config required
const dataIdC = configs.get( "conf_DataIdC" ) + ""; // config required
// 'java.lang.String' (String Obj) to javascript primitive 'string'

// Design-time Config Format Check
const numLower = parseFloat( lower );
engine.log( " AutomatedTask Lower Limit: " + numLower );
const numUpper = parseFloat( upper );
engine.log( " AutomatedTask Upper Limit: " + numUpper );
if( isNaN(numLower) ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {Lower} is not a number \n" );
}
if( isNaN(numUpper) ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {Upper} is not a number \n" );
}
if( numLower > numUpper ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {Lower} is greater than {Upper} \n" );
}


//// == Data Retrieving / ワークフローデータの参照 ==
// nothing (This Service Task is a CREATE type)


//// == Calculating / 演算 ==
let numDiff  = numUpper - numLower;
let mathRand = Math.random(); // Math.random(): 0.00 to 0.99
engine.log( " AutomatedTask Math.random(): " + mathRand );
let numRand  = mathRand * numDiff + numLower;
engine.log( " AutomatedTask Generated Random: " + numRand );


//// == Data Updating / ワークフローデータへの代入 ==
engine.setDataByNumber( dataIdC, new java.math.BigDecimal( numRand ) );


} //////// END "main()" ////////

Download

2021-07-05 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/number-generate-random-2021/
The Add-on import feature is available with Professional edition.

Notes

  1. Setting a range specification from 0 to 10 generates a number from 0.00 to 9.99.
  2. If a random number is required as a character string, consider using “String, Generate Password“. (0 starts, etc.)
  3. The format of the lower limit and upper limit depends on the JavaScript “parseFloat()” function.

Capture

Generates a random number. When a token reaches this automated step, a numerical value within the specified range is generated each time. The decimal part is rounded down toward 0 according to the workflow data definition.

See also

2 thoughts on “#Number: Generate Random”

  1. Pingback: Number, Generate Random – Questetra Support

  2. Pingback: String, Generate Password – Questetra Support

Comments are closed.

%d bloggers like this: