How to generate a random number several times or infinitely?

Hello I need for a project to generate infinitely a random number how can I do ?
I tryed that but it doesn’t work : while true do
task.wait()
local randomNumber = math.random(1, 9)
end

What part of what you tried doesn’t work?

I tried to generate infinitely a random number

Infinitely generating ?
Use

while true do
wait(some second so the game wont broke bc generate to fast)

print(math.random(number min, number max))

end ```

Yes but it’s work only with print if you don’t use print it doesn’t work

where do you want to make an infinite number? a gui?

No to choose a function example if randomNumber == 1 then use function one

Here is my code it doesn’t work (He generate just one random number) :
image

Could you not just do:

function generate_random_number(min : number, max : number)
local seed = Random.new();

local number = seed:NextInteger(min, max);

return number;
end;

local random_number = generate_random_number(1, 9);
print("Generated random number: " .. tostring(random_number));

Hope this helps. Sorry about markdown, done this on a mobile device.

What u said kinda make sense, damn i lost

@SpyKix_144, try the example I gave above ^

Try removing return randomNumber from the bottom of the loop.

Returning will break the loop.

2 Likes