FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Suggestions
   Software Suggestions
(Moderator: fry)
   random() and repeatability
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: random() and repeatability  (Read 2963 times)
swayzak


random() and repeatability
« on: Jan 3rd, 2005, 1:22am »

You can guess my goals from the subject, the question being how to best achieve preservation of our most interesting random()-seeded results. What I'm hoping for (and haven't found) is something like a post-processing Eclipse plugin that simply generates from random()-using program P a program P'1 containing fixed values at each iteration, up to the defined ceiling. Does such a thing exist? Is there an easier way to reach these goals with Processing?  
Considering eg. the limitations of pixel output for high-quality printing, I suspect there would be large demand for a tool that let you easily keep programmatic output of your favorites for further tweaking prior to ps/ai export, even if you did then have to contend with twelve hundred machine-generated functions.
And if no one's specifically requested this feature, then let this be my request
« Last Edit: Jan 3rd, 2005, 7:37pm by swayzak »  
amoeba

WWW
Re: random() and repeatability
« Reply #1 on: Jan 3rd, 2005, 11:34pm »

If I get you correctly you're looking for a way to create repeatable series of random numbers?
 
typically, a random number generator (RNG) takes a seed to start the sequence. in most cases (I assume that's what happens in Processing) the seed is taken to be the current time, so that you get a new sequence each time.
 
for an invariant sequence you have to use some other RNG than the one built in. the easiest option is to use java.util.Random, which allows you to instantiate it with a seed.  
 
Code:
java.util.Random rnd;
 
rnd=new java.util.Random(0); // number is the seed
 
float randomfloat=rnd.rndFloat(); // returns number 0..1

keeping the seed the same will give you the sequence each time.
 
if you're feeling adventurous and Java savvy, there is an excellent package called RngPack, see http://www.honeylocust.com/RngPack/. this contains several different RNGs, including the Mersenne Twister, which is slightly faster than java.util.Random.
 
for the record, I agree that it might be a useful feature to be able to set the initial random seed to a specific seed.
 

marius watz // amoeba
http://processing.unlekker.net/
swayzak


Re: random() and repeatability
« Reply #2 on: Jan 4th, 2005, 4:30pm »

Thanks for your response. Assuming Processing is using the standard java.util.Random (I haven't verified this) then it's true that a 48-bit number derived from the time in milliseconds is the PRNG seed. However, just repeating the sequence doesn't really address what I want to do; namely, small modifications by hand once the linear congruential formula has produced a likely candidate.
 
I'm in the process of hacking up a script that basically does what I want, but it requires function markup and in general would be better-done as part of Processing.
 
fry


WWW
Re: random() and repeatability
« Reply #3 on: Jan 4th, 2005, 5:26pm »

i think that generally the needs for randomness in p5 apps are much more basic than this. in later versions of processing we'll be adding a randomSeed() function which simply sets the seed of java.util.Random, or in other projects, i've just used an integer-based LFSR to get repeatable results in an animation or visualization.  
 
perhaps you could enlighten those of us more curious than mathematically inclined on what else would you want to be able to do with something more advanced?
 
amoeba

WWW
Re: random() and repeatability
« Reply #4 on: Jan 4th, 2005, 7:30pm »

on Jan 4th, 2005, 4:30pm, swayzak wrote:
However, just repeating the sequence doesn't really address what I want to do; namely, small modifications by hand once the linear congruential formula has produced a likely candidate.

 
Hmm, I have no idea what you're trying to do nor am I a math head, but it sounds like it could almost be a candidate for using genetic algorithms as a way to search through the parameter space of your function / algorithm / whatever. I doubt that controlling the RNG would be enough. Anyway, as Ben already said, I think that's outside the scope of Processing itself.
 
Good luck!
 

marius watz // amoeba
http://processing.unlekker.net/
swayzak


Re: random() and repeatability
« Reply #5 on: Jan 5th, 2005, 12:46am »

OK, I'll attempt to illustrate by example rather than handwaving
 
// DEFITERLIST mycolors
color[] mycolors = {#3a2424, #3b2425, #352325};
 
// DEFRANDFUNC chooseonecolor
// USEITERLIST mycolors
color chooseonecolor() {
  // choose color from mycolors
  return mycolors[int(random(mycolors.length))];
}
...
//ITERFUNC draw
//ITEROBJS x y c
draw() {
c = chooseonecolor();
x = random();
y = random();
 
fillPointwithColor(x,y,c);
}
 
// ITERSTART runLoop
// ITERCOUNT 5
runLoop(draw,5);
 
now when the loop runs, we get draw() replaced with drawITER1,drawITER2..etc
like:
 
drawITER1() {
(color) c = #3a2424;
(float) x = .5;
(float) y = .3;
 
fillPointwithColor(x,y,c);
}
 
drawITER2() {
(color) c = #352325;
(float) x = .9;
(float) y = .1;
 
fillPointwithColor(x,y,c);
}
 
and so on. I'm sure you see the possibilities in being able to make modifications to an arbitrary round once random() has produced something you generally like.
Ben: to address your other comment, I think even a simple logRandSeed(filename) for successive appension might well be generally useful.
« Last Edit: Jan 5th, 2005, 5:49am by swayzak »  
5cameron

WWW
Re: random() and repeatability
« Reply #6 on: Jan 9th, 2005, 7:58pm »

personally, what I do is define everything that is going to be random at the outset
 
say:
 
float randNum1 = random(100);
float randNum2 = random(200);
float randNum3 = random(1000);
 
then what you do is create a log text file. Append every random variable's value to the log file along with the date/time. Then if you get a good one, write down the date/time, and you can go into the log file and pull the values when you need them.
 
It can also be very helpful to take a screencap of your lo-res output and name the file the date/time.
 
-5
 
 
Pages: 1 

« Previous topic | Next topic »