|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
i need to do a randomisation of an array how do i do it?? i tried the rand() function but it returns some weird numbers with lots of decimal points....
thanks i really need help!! |
|
#2
|
|||
|
|||
|
If I understood you correctly this is what you want. It will print random line from @phrases array:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre> # Invoke srand; with a seed of the time and pid. If you are on a machine # which doesn't put the pid into $$ (ie. Macintosh, Win NT, etc...), change # this line to: srand(time ^ 22/7); srand(time ^ $$); # Now pluck our random phrase out of the @phrases array! But wait! This # only returns a number. $phrase = rand(@phrases); # Print out the Content-type header, so the browser knows what's going on. print "Content-type: text/htmlnn"; # Change this number into the text we want to return and print it! print $phrases[$phrase]; [/code] [This message has been edited by Pepe (edited November 27, 2000).] [This message has been edited by Pepe (edited November 27, 2000).] |
|
#3
|
|||
|
|||
|
thanks pepe..
u have solved part of my problem...in my case i have to randomise an array of string that i have extracted from my database..what u have written in the above post only get 1 string out from the array. if i use the rand() function that u have taught me, sometimes it will get back the same string from the array again.. anyway thanks for ur help.. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Randomisation??? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|