forrest-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan.Mate...@rzf.fin-nrw.de
Subject AW: [issues] (FOR-181) Use code-names for skins
Date Wed, 04 Aug 2004 14:34:01 GMT
> > How about a random number generator? Seriously. We could
> > put those items in a list, press the button, and see what
> > pops out. Does Ant have a random number generator?

Not a build in one that I am aware of.
You could use usual Java API during <scriptdef>.


Jan


<project>
    <scriptdef name="random" language="javascript">
        <attribute name="property"/>
        <attribute name="max"/>
        <attribute name="detail"/>
        <![CDATA[
            random = new java.util.Random();
            randomNr = random.nextDouble() * attributes.get("max");
            det = attributes.get("detail");
            if (det != null) {
                for (i=0; i<det; i++) randomNr = randomNr * 10;
                randomNr = randomNr - (randomNr % 1);
                for (i=0; i<det; i++) randomNr = randomNr / 10;
            }
            project.setNewProperty(attributes.get("property"), randomNr);
        ]]>
    </scriptdef>

    <random property="rnd.10.x"  max="10"/>
    <random property="rnd.25.x"  max="25"/>
    <random property="rnd.25.0"  max="25"  detail="0"/>
    <random property="rnd.100.4" max="100" detail="4"/>

    <echoproperties prefix="rnd"/>
</project>


[echoproperties] #Ant properties
[echoproperties] #Wed Aug 04 16:32:06 CEST 2004
[echoproperties] rnd.25.x=8.140765781088142
[echoproperties] rnd.10.x=3.310055226746628
[echoproperties] rnd.100.4=61.7307
[echoproperties] rnd.25.0=15


Mime
View raw message