views:

494

answers:

2

I want to get a random number using template toolkit. It doesn't have to be particularly random. How do I do it?

+1  A: 

From this post at Slashcode:

[slash@yaz slash]$ perl -MSlash::Test -leDisplay
[%
digits = [ 0 .. 9 ];
anumber = digits.rand _ digits.rand _ digits.rand;
anumber;
%]
^D
769
Michael Wales
A: 

Hmm, you might have issues if you don't have (or cannot import) Slash::Test. From a "vanilla" installation of TT, you can simply use the Math plugin:

USE Math;
GET Math.rand; # outputs a random number from 0 to 1

See this link in the template toolkit manual for more information on the Math plugin and the various methods.

Angelos

related questions