Login  Register

Re: Macro function for random seed?

Posted by Michael Schmid on Jan 21, 2010; 1:53pm
URL: http://imagej.273.s1.nabble.com/Copying-files-with-a-Macro-tp3689619p3689623.html

Hi Norbert,

sorry, no way to have a seed for the random number in a macro with  
the current ImageJ version.

You could consider writing a short plugin that is evoked via 'call':
Roughly like this (I have not tried it)

import ij.plugin.PlugIn;
import ij.util.Tools;
import java.util.Random;

public class Random_ implements PlugIn {
     static String random = new Random();
     public void run(String arg) {} //not used
     public void getRandom () {
         return Double.toString(random.nextDouble());
     }
     public void setSeed(String seedS) {
        random.setSeed((long)(tools.parseDouble(seedS)));
     }
}

In the macro:
   call("Random_.setSeed", mySeed);
   myRandomNumber = parseFloat(call("Random_.getRandom"));

Michael
________________________________________________________________

On 21 Jan 2010, at 12:48, Norbert Vischer wrote:

> Hello all,
>
> does the macro language allow to reproduce a random series from a  
> seed number?
>
> Obviously, random() does not accept any seed argument.
>
> best regards, Norbert