I need to pick a random item from the database and fairly account for every entry. When picking a random item from the above example, Elliot will only have one chance to be picked, John 4 chances and so on.
This would be a lot easier if you created a data type of ‘Entry’ with a User attached. Then, search for Entries, sort randomly and pick the first one one the list. That sort might not be completely mathematically random but for all intents and purposes it is…
It shouldn’t be hard to change this. Whenever your app makes changes to user’s entries just create or delete an Entry instead.
Yes you can do that like I told you, but not really with your current database structure… your database is the limiting factor here… It will be mathematically correct if you revise your database structure.
You can change it pretty easily for this case.
If you really don’t want to change it (which is the wrong solution), you need to do something along the lines of:
Calculate total entries
Assign entry numbers (e.g Elliot has 1, John 2-5, and Rachel 6-10)
Pick a number between 1 and the total entries
Work out who has that number using a loop to check the sum of all previous entries in the list
Bubbles random operations both :random item & random sort are not very random. Even with hundreds of options you usually end up with a few vastly over chosen values. (Especially bubble server side random sorting)
Dealt with this on my NFT generator. Ended up implementing chance.JS