Appian Community
Site
Search
Sign In/Register
Site
Search
User
DISCUSS
LEARN
SUCCESS
SUPPORT
Documentation
AppMarket
More
Cancel
I'm looking for ...
State
Suggested Answer
Replies
8 replies
Answers
1 answer
Subscribers
8 subscribers
Views
15440 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
General
Generate a random number within a specific range
brindas1
over 7 years ago
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.
OriginalPostID-257792
Discussion posts and replies are publicly visible
Top Replies
Peter Lewis
over 4 years ago
in reply to
mayureshs782
+1
Appian Employee
There's only one rand() function and it always returns a decimal between 0 and 1. So, you have to manipulate that number to get what you need. For example, the following would work for the scenario you…
Parents
0
chetany
A Score Level 1
over 7 years ago
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]
)
)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
Reply
0
chetany
A Score Level 1
over 7 years ago
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]
)
)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
Children
No Data