#rng
1 messages · Page 1 of 1 (latest)
math.random
and they prolly have a table of a bounch of random items
thats what im doing but im thinking it cant be this simple
Depends of how you want it to be
** You are now Level 26! **
Percentage based or weighted
im doing weighted rn is percentage based better? i see games use them more
I found a weight util for Roblox that was super super accurate to the given percentage, so I'd use weights.
can you elaborate? Im not sure what a weight util is
I just mean I was looking for my own solution to a similar issue, and found a nice module script via Google that helped me implement weighted randomness so I could select from a set of items.
is something along the lines of random num < cumilative weight loop
I can't quite remeber it, but I can find it one day and share it with you
alr bet
For a weighted one I did smth like this
local table = {}
local function add(string, times)
for i = 1 times do
table.insert(table,string)
end
end
-- then add your things
add("rock",10)
add("dirt",5)
local function choose()
print(table[math.random(1,#table)])
end
choose()
** You are now Level 10! **
Finally!
Here you go. It's a bit old (so it has no types or anything) but it's a nice little O.O.P object that you can use, instructions on how to use are in the comment at the top
I tested it by having it choose many many times, and the percentages equaled the weight it was given, so I trust this.
I found this solution somewhere online at some point, but I used the code to make this class.
you can always use random.new
instead of math.random
it would just be Random.New():NextInteger(1,#table) instead of math.random(1,#table) i think
moon tuner looks pretty nice ill trust that it works
yeah ill do that if moon tuner doesnt work or outdated during testing
Let me know if you have any issues, as I'd want to use it for myself.
I'll add types to it later this week.
i have a question on why you put sort everywhere?
I had to sort the weights so the :Choose function would work correctly
It basically checks each choice via a range that it builds off.
So keeping it sorted ensures it wouldn't be caught earlier by a higher weight choice
It's been a while since I looked at it more fully so it could be really stupid, I just know when I used it, it worked well lol
nah I reread it over should work nicely.
@worn niche when u used this did u implement a pity system outside? or your rolls had no pity system
** You are now Level 8! **
No I didn't, but you could reduce the weights of certain items by a pity factor and use the reset weights to default function when they get a good roll
👍 yeah thank you I’ll implement that in another module script