# Randomize Array of FTransform and compare if the elements are duplicated C++?

**URL:** <https://forums.unrealengine.com/t/randomize-array-of-ftransform-and-compare-if-the-elements-are-duplicated-c/628877>\
**Category:** C++\
**Tags:** UE4-20, unreal-engine, UE4, question, CPP\
**Created:** [August 15, 2022, 3:19pm UTC](https://forums.unrealengine.com/t/randomize-array-of-ftransform-and-compare-if-the-elements-are-duplicated-c/628877 "2022-08-15T15:19:51Z")\
**Posts on this page:** 1\
**Showing post:** 17

<div class="post-metadata">

**Author:** ![zeaf](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zeaf/32/1108035_2.png) [@zeaf](https://forums.unrealengine.com/u/zeaf)\
**Post date:** [August 16, 2022, 12:29pm UTC](https://forums.unrealengine.com/t/randomize-array-of-ftransform-and-compare-if-the-elements-are-duplicated-c/628877/17 "2022-08-16T12:29:55Z")

</div>

Well like I said earlier, after you call RandomLocation, you need to have a do while, otherwise it will just stop if the random transform returned is not one that hasn’t been used before. So you need to do something like:

```auto
do
{
	RandomLocation(Available, Location);
}
while (UsedLocations.ContainsByPredicate([Location](const FTransform Transform)
	{
		return Transform.GetLocation() == Location.GetLocation()
			&& Transform.GetRotation() == Location.GetRotation()
			&& Transform.GetScale3D() == Location.GetScale3D();
	}));

SpawnLocation = Location;
UsedLocations.Add(SpawnLocation);

```

But I don’t recommend this, this can potentially cause freezes

This will keep getting a random element until it finds one that is not in the UsedLocations array

---

_[View the full topic](https://forums.unrealengine.com/t/randomize-array-of-ftransform-and-compare-if-the-elements-are-duplicated-c/628877)._
