Operating System - HP-UX
1837182 Members
2624 Online
110113 Solutions
New Discussion

Re: unknown math function "rand"

 
Dewa Negara_4
Regular Advisor

unknown math function "rand"

Hi All,

I have a script that using rand function. When I tried to run it, I got an error below. Anyone know what the issue? Is there any patch need to be installed to resolve the issue? Please help.

Thanks.
Negara

unknown math function "rand"
while executing
"expr {int($m*rand())}"
(procedure "rand" line 3)
invoked from within
"rand 2"
invoked from within
"set isleft [rand 2]..."
invoked from within
"set initially_left [set isleft [rand 2]]..."
(file "./mkpasswd" line 108)


Santos
3 REPLIES 3
Steven E. Protter
Exalted Contributor

Re: unknown math function "rand"

RAND(3) Linux Programmerâ s Manual RAND(3)

NAME
rand, srand - random number generator.

SYNOPSIS
#include

int rand(void);

void srand(unsigned int seed);

DESCRIPTION
The rand() function returns a pseudo-random integer between 0 and
RAND_MAX.

The srand() function sets its argument as the seed for a new sequence
of pseudo-random integers to be returned by rand(). These sequences
are repeatable by calling srand() with the same seed value.

If no seed value is provided, the rand() function is automatically
seeded with a value of 1.


Seems like a standard function to me.

S
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Mark Grant
Honored Contributor

Re: unknown math function "rand"

I'm a bit confused here, what language is this script written with? It almost looks like shell but almost looks like C too.

If you are using C then you need to include stdlib as SEP points out above. If you are using shell, you need to use the $RANDOM (which is a bit rubbish really). It looks like whichever language you are using here doesn't have the "rand()" function you are looking for.

Never preceed any demonstration with anything more predictive than "watch this"
Matti_Kurkela
Honored Contributor

Re: unknown math function "rand"

As Mark Grant said, this looks a bit like C but some parts read like a shell script... is this Perl?

If it is, the next question will be: which version? "perl -v" will tell you that.

Older releases of HP-UX 11.0 had a very old Perl version by default. There are depots of
Perl 5.6.1 and Perl 5.8 available for free at software.hp.com: look in "development tools".
MK