# What Is NextInteger and how do I use them?

help with NextInteger

1. What do you want to achieve?
I want to know how do I use NextInteger and how to use it
2. What is the issue?
3. What solutions have you tried so far?
I saw the API about random and it talks about NextInteger but i didn’t understand what it said
1 Like

Im pretty sure `NextInteger` just gets a Random Integer

``````print(Random.new():NextNumber(0,10))
``````

If you want a whole number from this, you round it, but i would probably suggest `math.random` for that use

Haven’t ever had a reason to use a Random object, `but it just returns the next random number using a seed.` The first random number using the same seed, will always be the same. Therefore, the list of random numbers for each seed is the same for everytime a new random object is created with that seed.

So, the Random object should only be used in a situation where there should be randomness, but where the same random pattern will be replicated all the time. This is mostly used in terrain generation with a seed, like minecraft or terraria.

1 Like

Can you give an example? so it would be easier to understand

``````local Gen = Random.new(5)

for i = 1, 5 do
print(Gen:NextInteger(0, 5))
end

-- This should always print the same 5 random numbers, if I'm right
``````
1 Like

So, if i create another variable with the same code then the 5 random numbers would be different than the first 5?

When you create a new random object, it doesn’t care about existing random objects or any generation you’ve done. It starts over with it’s seed, and starts generating the same numbers everytime given that seed.

What `math.random` does is just generate a random number every time, with no way of predicting what it will be, unlike Random objects.

4 Likes

I think I understand now ty, ill try to make tests in studio

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.