homepage Welcome to WebmasterWorld Guest from 54.197.147.90
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Scaler keeps Random number from 4-10
Scaler keeps Random number from 4-10
StopSpam




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

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




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

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

StopSpam




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

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




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

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




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

ok yuour talking php

in working in perl
can i then still use:

$rank = rand(4, 10);

Glacai




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

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




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

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




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

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

StopSpam




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

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 ....

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved