Re: Macro function for random seed?
Posted by
Michael Schmid on
URL: http://imagej.273.s1.nabble.com/Copying-files-with-a-Macro-tp3689619p3689625.html
Hi Gabriel,
that's a good question! The seed will be lost if the plugin gets
removed by the Garbage Collector and the next time it will be
initialized using the default seed.
So one should avoid this:
public class Random_ implements PlugIn {
static Random random = new Random(); //(sorry, there was a
mistake in this line)
IJ.register(Random_.class); //protect static class variables
from gc
In practice, I don't remember having ever seen a plugin's static
variables being removed by the Garbage Collector, but maybe that's
because I usually have plenty of free memory...
Michael
________________________________________________________________
On 21 Jan 2010, at 15:29, Gabriel Landini wrote:
> On Thursday 21 Jan 2010 14:26:47 you wrote:
>> 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)
>
> I am curious, would the above work for subsequent independent calls
> of the
> plugin from the macro?
> I mean for how long would the seed remain valid?
>
> Cheers
>
> G.