Page 1 of 1

Random Number Range

Posted: Mon Sep 03, 2018 5:35 pm
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.

Re: Random Number Range

Posted: Tue Sep 04, 2018 9:03 am
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

Re: Random Number Range

Posted: Tue Sep 04, 2018 10:48 am
by soa
Good work Mark. Saved me a bit of messing round and achieves a god distribution over a 1000 calls.