Skip to content

Instantly share code, notes, and snippets.

@Atrachtanas
Created May 29, 2024 13:54
Show Gist options
  • Select an option

  • Save Atrachtanas/340a740336424e6f18bd06ffaa77da0d to your computer and use it in GitHub Desktop.

Select an option

Save Atrachtanas/340a740336424e6f18bd06ffaa77da0d to your computer and use it in GitHub Desktop.
// Define a function to generate a random number within a specified range
function getRandomNumber(min, max) {
// Math.random() generates a random number between 0 and 1
// We scale and shift it to be in the range [min, max]
return Math.floor(Math.random() * (max - min + 1)) + min;
}
// Access input range values using dot notation
let rangeFrom = input.Random_range_from;
let rangeTo = input.Random_range_to;
// Ensure that the range is valid
if (rangeFrom <= rangeTo) {
// Generate the random number using the custom function
let randomNumber = getRandomNumber(rangeFrom, rangeTo);
// Assign the generated random number to the output model
output.Rand = randomNumber;
} else {
// If the range is invalid, log an error message
log("Invalid range: 'Random_range_from' should be less than or equal to 'Random_range_to'");
// Optionally, you can set an error value or leave the output undefined
output.Rand = null;
}
// Ensure the result is returned
return output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment