I'm working with version 5.5 native pro-iv on a unix box. I'm needing to generate random numbers. Is there a way within pro4 that this could be done? Any help would be appreciated.
Thanks,
Joel

Random Number Generator
Started by jloflin, Nov 16 2004 08:18 PM
8 replies to this topic
#2
Posted 16 November 2004 - 09:02 PM
Joel,
Here's an ugly answer. Hopefully someone has something better for you.
Call an external awk script
# rand.awk -- test random number generation
BEGIN {
srand()
print rand()
}
You can then set the output to a system variable or place it in a file and retrieve the value.
hth,
Joseph
Here's an ugly answer. Hopefully someone has something better for you.
Call an external awk script
# rand.awk -- test random number generation
BEGIN {
srand()
print rand()
}
You can then set the output to a system variable or place it in a file and retrieve the value.
hth,
Joseph
#4
Guest_George_*
Posted 17 November 2004 - 06:01 PM
Here's a solution using ProIV code:
PRECISION(20)
#Numb1 = 2 ** 50
#Numb2 = INT((#Numb1 - 1) * FRAC(CTIME(@TIME) + (@DATE / 1000000000000)))
#Numb3 = #Numb1 - 1 - #Numb2
#Numb3 = INT(REM((#Numb2 * #Numb3),#Numb1))
#RANDOM = (#Numb3 / #Numb1) * 10000
PRECISION(20)
#Numb1 = 2 ** 50
#Numb2 = INT((#Numb1 - 1) * FRAC(CTIME(@TIME) + (@DATE / 1000000000000)))
#Numb3 = #Numb1 - 1 - #Numb2
#Numb3 = INT(REM((#Numb2 * #Numb3),#Numb1))
#RANDOM = (#Numb3 / #Numb1) * 10000
#8
Posted 18 November 2004 - 04:24 PM
Although I liked the idea of returning the answer to the question of life, the universe, and everything....I decided that this seemed like a good way to wake up properly 
I don't pretend that it's elegant....
N PARMS(#MULT)
PRECISION(20)
IF #MULT = 0 #MULT = 100;
$TERM = @TERM
#LEN = 1
WHILE #LEN > 0
#LEN = LEN($TERM)
IF $TERM(1,#LEN) IN-RANGE '0','9'
$TERM2 = $TERM2 + CONV(CONV($TERM(1,#LEN)) * 2 ** (#LEN - 1))
$TERM = $TERM(2,#LEN)
ELSE
$TERM2 = $TERM2 + CONV(ORD($TERM(1,#LEN)) * 2 ** (#LEN -1))
$TERM = $TERM(2,#LEN)
ENDIF
ENDWHILE
#NUM1 = CONV($TERM2)
#DD = CDATE(CDATE(@DATE,'DD'))
IF REM(#DD,2) = 0
#NUM1 *= @DATE
ELSE
#NUM1 /= @DATE
ENDIF
IF REM(CTIME(@TIME),2) = 0
#NUM1 /= CTIME(@TIME)
ELSE
#NUM1 *= CTIME(@TIME)
ENDIF
#NUM1 /= 1000000000000000
#RANDOM = ROUND((FRAC(#NUM1) * #MULT),0)
RETURN(#RANDOM)
Where this glogic would be called like #I = RAND_N(#MULT)

I don't pretend that it's elegant....
N PARMS(#MULT)
PRECISION(20)
IF #MULT = 0 #MULT = 100;
$TERM = @TERM
#LEN = 1
WHILE #LEN > 0
#LEN = LEN($TERM)
IF $TERM(1,#LEN) IN-RANGE '0','9'
$TERM2 = $TERM2 + CONV(CONV($TERM(1,#LEN)) * 2 ** (#LEN - 1))
$TERM = $TERM(2,#LEN)
ELSE
$TERM2 = $TERM2 + CONV(ORD($TERM(1,#LEN)) * 2 ** (#LEN -1))
$TERM = $TERM(2,#LEN)
ENDIF
ENDWHILE
#NUM1 = CONV($TERM2)
#DD = CDATE(CDATE(@DATE,'DD'))
IF REM(#DD,2) = 0
#NUM1 *= @DATE
ELSE
#NUM1 /= @DATE
ENDIF
IF REM(CTIME(@TIME),2) = 0
#NUM1 /= CTIME(@TIME)
ELSE
#NUM1 *= CTIME(@TIME)
ENDIF
#NUM1 /= 1000000000000000
#RANDOM = ROUND((FRAC(#NUM1) * #MULT),0)
RETURN(#RANDOM)
Where this glogic would be called like #I = RAND_N(#MULT)
Reply to this topic

0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users