xDeltaXen
(xDeltaXen)
October 3, 2021, 11:23pm
#1
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
xDeltaXen
(xDeltaXen)
October 3, 2021, 11:41pm
#3
I meant n as in the 10 in the code example not in a for loop
Haydz6
(Cookie)
October 3, 2021, 11:49pm
#4
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)