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
9 subscribers
Views
15552 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
ashman
over 7 years ago
Another work around
load
(
local!min:50,
local!max:100,
local!occurance:10,
local!arr1:Fixed(rand(local!occurance)*local!max,0),
local!placesToChange:where(local!arr1<local!min),
local!valuesToChange:index(local!arr1,local!placesToChange),
local!differenceToAdd:local!min-index(local!arr1,local!placesToChange),
local!updatedValues:local!min+local!valuesToChange,
local!finalAnswer:updatearray(local!arr1,local!placesToChange,local!updatedValues),
a!sectionLayout(
label: "Lorem Ipsum",
firstColumnContents: {
a!textField(
label: "minimum number",
labelPosition: "ABOVE",
value:local!min,
saveInto: {},
refreshAfter: "UNFOCUS",
validations: {}
),
a!textField(
label: "maximumn number",
labelPosition: "ABOVE",
value:local!max,
saveInto: {},
refreshAfter: "UNFOCUS",
validations: {}
),
a!textField(
label: "Occurance",
labelPosition: "ABOVE",
value: local!occurance,
saveInto: {},
refreshAfter: "UNFOCUS",
validations: {}
),
a!textField(
label: "Original Random numbers",
labelPosition: "ABOVE",
value:local!arr1,
saveInto: {},
refreshAfter: "UNFOCUS",
validations: {}
),
a!textField(
label: "places to change",
labelPosition: "ABOVE",
value:local!placesToChange,
saveInto: {},
refreshAfter: "UNFOCUS",
validations: {}
),
a!textField(
label: "values to change",
labelPosition: "ABOVE",
value:local!valuesToChange,
saveInto: {},
refreshAfter: "UNFOCUS",
validations: {}
),
a!textField(
label: "Difference To add",
value:local!differenceToAdd,
labelPosition: "ABOVE",
saveInto: {},
refreshAfter: "UNFOCUS",
validations: {}
),
a!textField(
label: "Updated values",
value:local!updatedValues,
labelPosition: "ABOVE",
saveInto: {},
refreshAfter: "UNFOCUS",
validations: {}
),
a!textField(
label: "Final answer",
value:local!finalAnswer,
labelPosition: "ABOVE",
saveInto: {},
refreshAfter: "UNFOCUS",
validations: {}
)
},
validations: {}
)
)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
Reply
0
ashman
over 7 years ago
Another work around
load
(
local!min:50,
local!max:100,
local!occurance:10,
local!arr1:Fixed(rand(local!occurance)*local!max,0),
local!placesToChange:where(local!arr1<local!min),
local!valuesToChange:index(local!arr1,local!placesToChange),
local!differenceToAdd:local!min-index(local!arr1,local!placesToChange),
local!updatedValues:local!min+local!valuesToChange,
local!finalAnswer:updatearray(local!arr1,local!placesToChange,local!updatedValues),
a!sectionLayout(
label: "Lorem Ipsum",
firstColumnContents: {
a!textField(
label: "minimum number",
labelPosition: "ABOVE",
value:local!min,
saveInto: {},
refreshAfter: "UNFOCUS",
validations: {}
),
a!textField(
label: "maximumn number",
labelPosition: "ABOVE",
value:local!max,
saveInto: {},
refreshAfter: "UNFOCUS",
validations: {}
),
a!textField(
label: "Occurance",
labelPosition: "ABOVE",
value: local!occurance,
saveInto: {},
refreshAfter: "UNFOCUS",
validations: {}
),
a!textField(
label: "Original Random numbers",
labelPosition: "ABOVE",
value:local!arr1,
saveInto: {},
refreshAfter: "UNFOCUS",
validations: {}
),
a!textField(
label: "places to change",
labelPosition: "ABOVE",
value:local!placesToChange,
saveInto: {},
refreshAfter: "UNFOCUS",
validations: {}
),
a!textField(
label: "values to change",
labelPosition: "ABOVE",
value:local!valuesToChange,
saveInto: {},
refreshAfter: "UNFOCUS",
validations: {}
),
a!textField(
label: "Difference To add",
value:local!differenceToAdd,
labelPosition: "ABOVE",
saveInto: {},
refreshAfter: "UNFOCUS",
validations: {}
),
a!textField(
label: "Updated values",
value:local!updatedValues,
labelPosition: "ABOVE",
saveInto: {},
refreshAfter: "UNFOCUS",
validations: {}
),
a!textField(
label: "Final answer",
value:local!finalAnswer,
labelPosition: "ABOVE",
saveInto: {},
refreshAfter: "UNFOCUS",
validations: {}
)
},
validations: {}
)
)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
Children
No Data