[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index]
[Date Index]
[Thread Index]
[SQR-USERS Info]
[SQRUG Home Page]
Re: Random text generation
Tony,
I attached a "poor man's random number generator" I wrote in SQR. If
you seed it with the same number, you can reproduce sets of "random"
numbers. If you use a different seed each time (say the current
date-time) it produces pretty good random numbers. You could use this
to get your string:
#include 'random.sqh'
begin-program
do start_random(5) !this is the seed
move 0 to #count
while #count < 3
do get_random(1, 36, #index)
let $char = substr('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', #index, 1)
concat $char with $random_string
add 1 to #count
end-while
end-program
Hope this helps,
Eric
Dorman, Tony wrote:
>Hello all,
>
>I have a need to generate a random emplid to be used in a select statement.
>The emplid is a mixture of text and numeric characters (such as "B2D7XG"). If
>I can generate the first three characters, I'll be able to use the 'LIKE'
>operand and get a decent sample. Has anyone developed code for a situation
>such as this? Any advice will be appreciated. Thanks!
>
>
> - Tony
>
>
#DEFINE RANDOM_NUM1 112792783
#DEFINE RANDOM_NUM2 9893
begin-procedure start_random(#random_seed)
let #_random_number = mod(#random_seed, {RANDOM_NUM2}) / {RANDOM_NUM2}
end-procedure start_random
begin-procedure get_random(#low, #high, :#return)
add .001 to #_random_number
let #temp = #_random_number * {RANDOM_NUM1}
let #_random_number = mod(#temp, {RANDOM_NUM2}) / {RANDOM_NUM2}
let #range = #high - #low
let #return = #_random_number * #range + #low
let #return = round(#return, 0)
end-procedure get_random