• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 132
  • Last Modified:

randomising

Can someone please write me a quick script that will randomise a number between two values predifined and write this number to a text file called Random.txt.

thanks
0
wormboy__6
Asked:
wormboy__6
1 Solution
 
KennyIT Application ExecutiveCommented:
This will do it :

$Num = int(rand(24));
open (OUT, ">out.txt");
print OUT $Num;
close (OUT);
0
 
wormboy__6Author Commented:
But how can i randomise a number between 2 predefined numbers...

eg if i have two strings

$Num1 = 100
$Num2 = 200

how can i generate a number between these two strings then write it to a txt file.
0
 
monasCommented:
$num = $num1 + int($num2-$num1+1);
0
 
monasCommented:
sorry,

$num = $num1 + int(rand($num2-$num1+1));
0
 
jhurstCommented:
between or including - sorry, being picky here, but monas will generate values 100..200 inclusive, not between.  But more to the point, this is not random since the rand() will always seed with the same value.  You need an srand() to set the seed so that thewy are different.
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now