Random Number Range

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
soa
Posts: 339
Joined: Mon Dec 07, 2015 3:15 pm

Random Number Range

Post by soa »

LANSA's RAndnom_number_generator BIF returns a number between 0 and 1. Has anybody out got a neat trick to this this into a range, e.g. Integers between 1 and 15. I had an RPG based BIF that did this trick but it doesn't work in RDMLX.
MarkD
Posts: 692
Joined: Wed Dec 02, 2015 9:56 am

Re: Random Number Range

Post by MarkD »

Try

Code: Select all

Mthroutine Name(Random)
Define_Map For(*INPUT) Class(#Std_int) Name(#Maximum)
Define_Map For(*RESULT) Class(#Std_int) Name(#Result)
Define Field(#Global_RandomValue) Type(*PACKED) Length(7) Decimals(6)
Use Builtin(RANDOM_NUM_GENERATOR) To_Get(#Global_RandomValue)
#Result := (#Global_RandomValue * #Maximum) + 1
Endroutine
soa
Posts: 339
Joined: Mon Dec 07, 2015 3:15 pm

Re: Random Number Range

Post by soa »

Good work Mark. Saved me a bit of messing round and achieves a god distribution over a 1000 calls.
Post Reply