Welcome to WebmasterWorld Guest from 54.196.224.166

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Scaler keeps Random number from 4-10

Scaler keeps Random number from 4-10

     

StopSpam

1:13 pm on Aug 12, 2003 (gmt 0)

10+ Year Member



Scaler keeps Random number from 4-10

i need a $scaler that contains a random number between 4 and 10 ...

in my perl book i found the function SRAND but i have no idea how to use it and there is only one sample code wish is not what i needed it shows radom text whill i need numbers....

$rank = "$random4_10";

How can i make a code that each time i run the script
the scaler $rank contains a different number between 4 to 10

so it may contain: 4 5 6 7 8 9 or 10

Glacai

1:40 pm on Aug 12, 2003 (gmt 0)

10+ Year Member



srand is just to seed the generator
$rank = rand(4, 10);

StopSpam

3:31 pm on Aug 12, 2003 (gmt 0)

10+ Year Member



Hi Glacai...
thanks for your reply and wecome to WebmastersWorld

im new to srank in fact whole cgi scripting ect
learning sinse few months now ...

so i just include this ;
$rank = rand(4, 10);

or do i need to include a extra line as well to start the random tool?

like:

srand; my book says you may only include once ...

so i add to top of script this?corect me if i am wrong;

srand;

then
$rank = rand(4, 10);

thats all right?

thx

Glacai

4:28 pm on Aug 12, 2003 (gmt 0)

10+ Year Member



Hi StopSpam, thanks for the welcome but I been around coming up to a year! but all the help I can give is usually already answered.

Anyway I don't think you need to use srand in the latest php but if you do yes, you should only seed it once each execution.

Sorry forgot, you need to seed with a number, usually something made from the date.

StopSpam

4:47 pm on Aug 12, 2003 (gmt 0)

10+ Year Member



ok yuour talking php

in working in perl
can i then still use:

$rank = rand(4, 10);

Glacai

4:59 pm on Aug 12, 2003 (gmt 0)

10+ Year Member



Sorry, yeah its nearly the same except it only takes max number, you don't need to call srand but I would look it up to find the best way to seed it.

$rank = rand(7) + 4;

StopSpam

7:01 pm on Aug 12, 2003 (gmt 0)

10+ Year Member



hi this is working i now get :

random number is:5.18599890451878
random number is:7.94239684566855
random number is:10.9349901601672

i use this to remove the . and nunmbers behind first number:

$rank = rand(7) + 2;
$c = "$rank";
$d = unpack("A1" , $c);
print "$d \n";

i now get clean numbers from 1 hill 9

thanks i could not have done it without you ...

this is a nice code snippet for a random number

;-)

Glacai

10:00 pm on Aug 12, 2003 (gmt 0)

10+ Year Member



Or even,
$rank = int(rand(7)) + 2;

StopSpam

11:24 pm on Aug 12, 2003 (gmt 0)

10+ Year Member



yes thats far better then how i thit it ...
this is perfect ...

your a real pro ;-)

were thit you learned this line?

i got the oreily perl cook book
but it has not these codedings

its limmited when it comes to radomnness

in fact i havent seen this code before

thank you ....