pv.random3D(target, parent);

Could someone explain when pv.random3D(target, parent); is used?
like PVector pv = PVector.random3D(this);
What are target and parent referring to?

  • The parameter target refers to an existing PVector you pass to it.
  • That is, if you’d prefer to use a PVector object you already have rather than getting a new 1 from random3D().
  • The parameter parent refers to a PApplet sketch.
  • It tells to random3D() to use a PApplet’s own random() instead of Math.random().
1 Like

//parent   PApplet: current PApplet instance
//target   PVector: the target vector (if null, a new vector will be created)

PVector pv = PVector.random3D();


// -----------------------------


1 Like

Thank you GoToLoop and Chrisir for the answers.
A remaining question is: why did Processing make their own random function?
What is the difference or advantage between both?

1 Like

Thanks, GoToLoop, but it still isn’t totally clear to me.
The randomSeed() function would secure that the program, when re-run, would have the same random numbers as previously? But doesn’t plain java have Random(long seed) as well?
I still do not understand the difference between both random functions.

Processing provides its own simplified API so its users don’t need to know Java’s API:

Searching in the PVector class I found:

random3D(PApplet parent)
Make a new 3D unit vector with a random direction using Processing’s current random number generator

But I could find neither in the PAplet class information about this ‘current’ generator.

Method PApplet::random() just uses an internal Random instance as field internalRandom:

I am sorry, maybe it’s simple but I just don’t get it.
If the PApplet method random(), just uses plain Java.util.Random Class methods, with some extra code, to avoid wrong parameter insertion, where is the difference between

What is the advantage of the ‘parent’ parameter? When would I use it?

It’s about simplification of usage. :flushed:

Almost nothing, just a matter of taste. :yum:
We’d use it if we wanna follow sketch’s current seed value. :seedling:

1 Like