# Clamp vs random in range blueprints

**URL:** <https://forums.unrealengine.com/t/clamp-vs-random-in-range-blueprints/411589>\
**Category:** Blueprint\
**Tags:** unreal-engine, clamp, question\
**Created:** [December 7, 2017, 2:05pm UTC](https://forums.unrealengine.com/t/clamp-vs-random-in-range-blueprints/411589 "2017-12-07T14:05:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_81db16ff1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_81db16ff1](https://forums.unrealengine.com/u/anonymous_user_81db16ff1)\
**Post date:** [December 7, 2017, 2:05pm UTC](https://forums.unrealengine.com/t/clamp-vs-random-in-range-blueprints/411589/1 "2017-12-07T14:05:10Z")

</div>

well i am looking at advanced blueprints 1.1 at content examples and i cant understand the difference between them. 1) They appear to do the same thing at first sight, is there any hidden usage?

Also

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/7/3/373114fd59e8419af899f5df4365212e7591e339.png)

1. we ■■■■ on the variable “number of meshes” even if it has a number for example -100?

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/4/7/14727ba72941296c628ef6ea521792d146c4c28c.png)

1. what is the last index, i mean it gets the current index the loop has each time…?

2. since the meshes to spawn array has only 1 entry (SM\_lightsculpture) , how it puts cubes too on my play game screen, example below

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/1/5/3150f1690c6c5367105d375062e09a9b5541bd19.png)

basically if you can explain the whole random mesh from array thing ( i know what array does and etc, i mean explain the logic)  
and lastly here is the whole blueprint if you wanna check things

[https://docs.unrealengine.com/latest/images/Resources/ContentExamples/Blueprints\_Advanced/1\_1/AdvBP\_1\_1\_ConstructionScript.jpg](https://docs.unrealengine.com/latest/images/Resources/ContentExamples/Blueprints_Advanced/1_1/AdvBP_1_1_ConstructionScript.jpg)

---

<div class="post-metadata">

**Author:** ![Kibblesticks](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kibblesticks](https://forums.unrealengine.com/u/Kibblesticks)\
**Post date:** [December 7, 2017, 6:09pm UTC](https://forums.unrealengine.com/t/clamp-vs-random-in-range-blueprints/411589/2 "2017-12-07T18:09:18Z")

</div>

**1)** The difference between _Clamp_ and _Random Int in Range_ is that _Clamp_ will take an Integer input and if that integer is outside the Min and Max it’ll set it to whichever is closer.

For example, if you have a _Clamp_ with Min:10, Max:20, and input the value “2”, the clamp will change “2” into “10”. If you input the value “10000”, the _Clamp_ will change the value to “20”. If you input “15” the clamp would do nothing as the value falls between the Min (10) and Max (20).  
In the screenshot you posted, clamp simply makes sure the player can’t input a value higher than 1000, or less than 0.

_Random Int in Range_ simply generates a completely random integer between the Min and Max. So if you set Min:1 and Max:5, you would randomly get 1,2,3,4, or 5 as an output value.

**2/3)** It’s a way to get a random item from an array. If you have an array with 50 items, the Last Index is 49 (0 counts as an index too). If you set the _Last Index_ as the Max value in a _Random Int in Range_, you will get any random index in that array. You can then use that index number to “Get” the relevant item from the array.

Example:

If we have an array of toys, it might look like this:

- 0 - Teddy bear
- 1 - Ball
- 2 - Doll
- 3 - Rattle

_Last Index_ gets the final index of the Array it’s attached to. In our example, _Last Index_ would return “3”, as that’s the last item.

By plugging the _Last Index_ into the Max value of _Get Random Int in Range_, you can get any value between the min and max of the array; in this case, 0,1,2, or 3.

The _Get_ node pulls an item from an array at the given index. So if we input a value of “2” into the _Get_ node, for our example array the output would be “Doll”.

The _Get_ node will use the random number generated by _Get Random Int in Range_ to pull that item from the array. It could be anything between the Min (0), and the Last Index (whatever the final index of the array is).

As for the rest I can’t really help as I haven’t looked at the example project. Hope this helps answer some of your questions.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_81db16ff1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_81db16ff1](https://forums.unrealengine.com/u/anonymous_user_81db16ff1)\
**Post date:** [December 7, 2017, 6:43pm UTC](https://forums.unrealengine.com/t/clamp-vs-random-in-range-blueprints/411589/3 "2017-12-07T18:43:00Z")

</div>

well thank you man you for answering questions i understood everything. Only thing that remains unanswered is the fact that as it shows in picture n3, it has more than 1 type of mesh, while the array named meshes to spawn has only one index at number 0 the light sculpture mesh. Any thoughts anyone?
