# Generating Random number inside a For loop within Construction Script

**URL:** <https://forums.unrealengine.com/t/generating-random-number-inside-a-for-loop-within-construction-script/333229>\
**Category:** Blueprint\
**Tags:** random-numbers, unreal-engine, construction-script, Blueprint, question\
**Created:** [September 24, 2015, 9:05am UTC](https://forums.unrealengine.com/t/generating-random-number-inside-a-for-loop-within-construction-script/333229 "2015-09-24T09:05:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_2a687cc6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2a687cc6](https://forums.unrealengine.com/u/anonymous_user_2a687cc6)\
**Post date:** [September 24, 2015, 9:05am UTC](https://forums.unrealengine.com/t/generating-random-number-inside-a-for-loop-within-construction-script/333229/1 "2015-09-24T09:05:44Z")

</div>

I am trying to use a Random number inside a range. This number is being generated inside a for loop within Construction Script of my Actor. I want to have a random number everytime loop body is executed, but it seems that the random number is generated only on first pass of the loop and same number is used in next loop passes. Anybody faced this problem before?

 ![59968-construction.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/1/a/21a067b961b99092a13003df2df69b2842a969be.png)

---

<div class="post-metadata">

**Author:** ![Sean\_Flint](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sean\_Flint](https://forums.unrealengine.com/u/Sean_Flint)\
**Post date:** [September 24, 2015, 2:53pm UTC](https://forums.unrealengine.com/t/generating-random-number-inside-a-for-loop-within-construction-script/333229/2 "2015-09-24T14:53:44Z")

</div>

Hello ambhar,

Unfortunately, I have been unable to reproduce the issue you are having. I was able to use a for loop to generate a random integer in the construction script, and I was getting a different value each time the loop body executed.

Are there any other details that you may have left out that could be helpful in reproducing? Also, if you are willing, you could create a test project that reproduces the issue you are having, and zip it up. If you upload that either here or on dropbox and provide me with a link, that would allow me to get a better understanding of exactly what is causing the error that you are experiencing.

Regards,

Flint

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2a687cc6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2a687cc6](https://forums.unrealengine.com/u/anonymous_user_2a687cc6)\
**Post date:** [September 24, 2015, 3:07pm UTC](https://forums.unrealengine.com/t/generating-random-number-inside-a-for-loop-within-construction-script/333229/3 "2015-09-24T15:07:34Z")

</div>

Hey ,  
I think I found the problem. I was trying to change the mesh in some instances of InstancedStaticMesh. But I believe it is not possible to add different Meshes to the different instances of a single InstancedStaticMesh.  
Thanks

---

<div class="post-metadata">

**Author:** ![ND\_Dwight](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ND\_Dwight](https://forums.unrealengine.com/u/ND_Dwight)\
**Post date:** [June 11, 2016, 1:54pm UTC](https://forums.unrealengine.com/t/generating-random-number-inside-a-for-loop-within-construction-script/333229/4 "2016-06-11T13:54:54Z")

</div>

That little info of yours helped me a lot. Thanks for sharing your solution/mistake.
