Table.create not returning diff random nums

So I want to qucikly create an array of n number of random numbers but they re not all different they are just the same random number

table.create(10, math.random())

Return:

{
[1] = 0.4061350279337175,
[2] = 0.4061350279337175,
[3] = 0.4061350279337175,
[4] = 0.4061350279337175,
[5] = 0.4061350279337175,
[6] = 0.4061350279337175,
[7] = 0.4061350279337175,
[8] = 0.4061350279337175,
[9] = 0.4061350279337175,
[10] = 0.4061350279337175
}

How to I fix this? i do want to use table.create because it is quick and easy. I would like to avoid creating a whole function just to get an array of random nums

for i = 1, n do --repeats the loop n times
   table.create(1, math.random())
end

Tell me if this works :slight_smile:

I meant n as in the 10 in the code example not in a for loop

table.create only allocates space for variables to speed up inserting.

You would instead need to do

local RandomNumbers = table.create(10) --Allocates space for the 10 numbers for speed

for i = 1,10 do
table.insert(RandomNumbers, math.random())
end
1 Like

I meant that you can replace n with whatever you want (in this case 10)