# Generate a random number within a specific range

Hi all,
Is there a way to generate a random number within a specific range? For example, I want to generate a random number between 60 to 90. Can I able to do it using Appian functions? Using rand() function I can able to generate a random 2, 3, 4 .... digit numbers but not within a specific range.

Discussion posts and replies are publicly visible

Parents
• Here's another solution:
For your case ri!upper will be 90 and ri!lower will be 60

with(

local!possibleNumbers: difference(
1+enumerate(ri!upper),
1 + enumerate(ri!lower)
),

local!count: length(local!possibleNumbers),

local!randomIndex: tointeger(local!count*(rand())),

if(local!randomIndex =0,
local!possibleNumbers[tointeger(local!count*(rand()))],

local!possibleNumbers[local!randomIndex]
)

)
• Here's another solution:
For your case ri!upper will be 90 and ri!lower will be 60

with(

local!possibleNumbers: difference(
1+enumerate(ri!upper),
1 + enumerate(ri!lower)
),

local!count: length(local!possibleNumbers),

local!randomIndex: tointeger(local!count*(rand())),

if(local!randomIndex =0,
local!possibleNumbers[tointeger(local!count*(rand()))],

local!possibleNumbers[local!randomIndex]
)

)
Children
No Data