# pv.random3D(target, parent);

**URL:** <https://discourse.processing.org/t/pv-random3d-target-parent/24442>\
**Category:** Beginners\
**Created:** [October 8, 2020, 3:59pm UTC](https://discourse.processing.org/t/pv-random3d-target-parent/24442 "2020-10-08T15:59:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![J\_Silva](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@J\_Silva](https://discourse.processing.org/u/J_Silva)\
**Post date:** [October 8, 2020, 3:59pm UTC](https://discourse.processing.org/t/pv-random3d-target-parent/24442/1 "2020-10-08T15:59:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [October 8, 2020, 4:13pm UTC](https://discourse.processing.org/t/pv-random3d-target-parent/24442/2 "2020-10-08T16:13:47Z")

</div>

> [@J\_Silva](#):
>
> 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()**.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 8, 2020, 4:17pm UTC](https://discourse.processing.org/t/pv-random3d-target-parent/24442/3 "2020-10-08T16:17:15Z")

</div>

```auto

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

PVector pv = PVector.random3D();

println(pv);

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

PVector.random3D(pv);

println(pv);

```

---

<div class="post-metadata">

**Author:** ![J\_Silva](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@J\_Silva](https://discourse.processing.org/u/J_Silva)\
**Post date:** [October 8, 2020, 6:13pm UTC](https://discourse.processing.org/t/pv-random3d-target-parent/24442/4 "2020-10-08T18:13:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [October 8, 2020, 6:28pm UTC](https://discourse.processing.org/t/pv-random3d-target-parent/24442/5 "2020-10-08T18:28:27Z")

</div>

> [@J\_Silva](#):
>
> Why did Processing make their own random function?

> **[randomSeed() / Reference](https://processing.org/reference/randomSeed_.html)**
>
> Sets the seed value for random(). By default, random() produces different results each time the program is run. Set the seed parameter to a constant to return the same pseudo-rand…

---

<div class="post-metadata">

**Author:** ![J\_Silva](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@J\_Silva](https://discourse.processing.org/u/J_Silva)\
**Post date:** [October 8, 2020, 7:17pm UTC](https://discourse.processing.org/t/pv-random3d-target-parent/24442/6 "2020-10-08T19:17:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [October 8, 2020, 7:35pm UTC](https://discourse.processing.org/t/pv-random3d-target-parent/24442/7 "2020-10-08T19:35:02Z")

</div>

> [@J\_Silva](#):
>
> But doesn’t plain Java have Random(long seed) as well?

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

---

<div class="post-metadata">

**Author:** ![J\_Silva](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@J\_Silva](https://discourse.processing.org/u/J_Silva)\
**Post date:** [October 8, 2020, 8:05pm UTC](https://discourse.processing.org/t/pv-random3d-target-parent/24442/8 "2020-10-08T20:05:59Z")

</div>

Searching in the [PVector class](https://processing.github.io/processing-javadocs/core/index.html?processing/core/PVector.html) 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](https://processing.github.io/processing-javadocs/core/processing/core/PApplet.html) information about this ‘current’ generator.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [October 8, 2020, 10:54pm UTC](https://discourse.processing.org/t/pv-random3d-target-parent/24442/9 "2020-10-08T22:54:47Z")

</div>

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

> <https://github.com/processing/processing/blob/processing-0270-3.5.4/core/src/processing/core/PApplet.java#L5107-L5130>

---

<div class="post-metadata">

**Author:** ![J\_Silva](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@J\_Silva](https://discourse.processing.org/u/J_Silva)\
**Post date:** [October 9, 2020, 12:10am UTC](https://discourse.processing.org/t/pv-random3d-target-parent/24442/10 "2020-10-09T00:10:17Z")

</div>

> [@GoToLoop](#):
>
> 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](https://www.tutorialspoint.com/java/util/java_util_random.htm), with some extra code, to avoid wrong parameter insertion, where is the difference between

> [@GoToLoop](#):
>
> It tells to **random3D()** to use a PApplet’s own **random()** instead of Math. **random()**.

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

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [October 9, 2020, 4:04am UTC](https://discourse.processing.org/t/pv-random3d-target-parent/24442/11 "2020-10-09T04:04:09Z")

</div>

> [@J\_Silva](#):
>
> , where is the difference between

It’s about simplification of usage. 😳

> [@J\_Silva](#):
>
> What is the advantage of the ‘parent’ parameter? When would I use it?

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