# How can I create a random Vector?

**URL:** <https://forums.unrealengine.com/t/how-can-i-create-a-random-vector/282561>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [May 5, 2014, 1:32pm UTC](https://forums.unrealengine.com/t/how-can-i-create-a-random-vector/282561 "2014-05-05T13:32:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_482d02a4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_482d02a4](https://forums.unrealengine.com/u/anonymous_user_482d02a4)\
**Post date:** [May 5, 2014, 1:32pm UTC](https://forums.unrealengine.com/t/how-can-i-create-a-random-vector/282561/1 "2014-05-05T13:32:32Z")

</div>

How to create a Random Vector in C++ ?  
e.g. create objects at random locations.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_482d02a4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_482d02a4](https://forums.unrealengine.com/u/anonymous_user_482d02a4)\
**Post date:** [May 5, 2014, 1:40pm UTC](https://forums.unrealengine.com/t/how-can-i-create-a-random-vector/282561/2 "2014-05-05T13:40:23Z")

</div>

wiki:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

```
FVector SpawnVector;
SpawnVector.X = FMath::FRandRange(0, 100);
SpawnVector.Y = FMath::FRandRange(0, 100);
SpawnVector.Z = FMath::FRandRange(0, 100);

```

---

<div class="post-metadata">

**Author:** ![Dieselhead](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dieselhead](https://forums.unrealengine.com/u/Dieselhead)\
**Post date:** [May 5, 2014, 1:45pm UTC](https://forums.unrealengine.com/t/how-can-i-create-a-random-vector/282561/3 "2014-05-05T13:45:19Z")

</div>

Also

```
// Random Vector with Length == 1
 FRandomStream rand;
 rand.GenerateNewSeed();
    
 FVector randVector = rand.GetUnitVector();
```

---

<div class="post-metadata">

**Author:** ![MulleDK19](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MulleDK19](https://forums.unrealengine.com/u/MulleDK19)\
**Post date:** [May 5, 2014, 1:55pm UTC](https://forums.unrealengine.com/t/how-can-i-create-a-random-vector/282561/4 "2014-05-05T13:55:42Z")

</div>

FMath::VRand();

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_482d02a4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_482d02a4](https://forums.unrealengine.com/u/anonymous_user_482d02a4)\
**Post date:** [May 5, 2014, 2:15pm UTC](https://forums.unrealengine.com/t/how-can-i-create-a-random-vector/282561/5 "2014-05-05T14:15:45Z")

</div>

when using this vector i get  
error C2039: ‘RandomUnitVector’ : is not a member of ‘FVector’

---

<div class="post-metadata">

**Author:** ![MulleDK19](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MulleDK19](https://forums.unrealengine.com/u/MulleDK19)\
**Post date:** [May 5, 2014, 3:21pm UTC](https://forums.unrealengine.com/t/how-can-i-create-a-random-vector/282561/6 "2014-05-05T15:21:29Z")

</div>

Sorry. It’s FMath::VRand().
