ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilbert Rebhan <>
Subject Re: random number generator
Date Sat, 21 Jul 2007 07:09:01 GMT

Mario Madunic wrote:
> Hi,
> I'm trying to generate a random number to be used as a temporary directory name
> through a multi step xslt process. I'm using Ant 1.6.5 and Java 1.6.0-b105

> I receive the following error
>    [random] Jul 20, 2007 9:11:27 PM org.apache.bsf.BSFManager exec
>    [random] SEVERE: Exception :
>    [random]
> org.apache.bsf.BSFException: JavaScript Error: Internal Error:
> org.mozilla.javascript.EcmaError: ReferenceError: "self" is not defined.

if you're already use BSF with <script> task i would recommend
JRuby, get the JRuby.jar from =

so it's a simple as =

<target name="depends">
   <script language="ruby">
     $project.setProperty "myrand", rand(4711).to_s

<target name="main" depends="depends">
     $${myrand} == ${myrand}

      [echo] ${myrand} == 718
Total time: 1 second

Just put an integer to the Kernel#rand method.
If you want a floating point number, just use
rand without (integer) =

<script language="ruby">
     $project.setProperty "myrand", rand.to_s

Regards, Gilbert

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message