# Math.random reusing same values?

**URL:** <https://forum.defold.com/t/math-random-reusing-same-values/76642>\
**Category:** Questions\
**Created:** [April 17, 2024, 8:03pm UTC](https://forum.defold.com/t/math-random-reusing-same-values/76642 "2024-04-17T20:03:50Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![selimanac](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/selimanac/32/6397_2.png) [@selimanac](https://forum.defold.com/u/selimanac)\
**Post date:** [April 17, 2024, 8:40pm UTC](https://forum.defold.com/t/math-random-reusing-same-values/76642/2 "2024-04-17T20:40:27Z")

</div>

You have to throw away the first one or two random numbers.

> [@Lua math.random problem](https://forum.defold.com/t/lua-math-random-problem/19372/18):
>
> Ah, I see. Well, hmm, if you throw away the first one or two random numbers you start to get the kind of variation that is to be expected: -- os.time() seems to work equally well math.randomseed(socket.gettime()) math.random() math.random() print(math.random(1,3)) Not optimal. Perhaps we can deal with this better internally in the engine…

```lua
math.randomseed(socket.gettime()) 
math.random() 
math.random()
math.random()

```

---

_[View the full topic](https://forum.defold.com/t/math-random-reusing-same-values/76642)._
