Source language: Translate to:

Efficient Way To Do "Weighted" Random Generation?

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Efficient Way To Do "Weighted" Random Generation?

Postby DantesGame » Mon Jan 26, 2015 11:26 am

I was up late last night doing some research on how to do weighted random number/element generation and found this article in the forums...
viewtopic.php?p=21319

...and this external source on random generation:
http://chancejs.com/#weighted

These sound like what I'm looking to do but is there a more efficient way to generate weighted numbers/elements than having to list X,X,X,X,X a number of times in an array?

If I have four objects: apples, oranges, pears, bananas and I want apples to come up 50% of the time, oranges to come up 25% of the time, pears 5%, and bananas 20%, do I really have to list them 50 times, 25 times, 5 times, and 20 times or is there another math function/variable storage process to handle that more efficiently?

Does that make sense?
DantesGame
 
Posts: 29
Joined: Sun Jun 08, 2008 1:15 pm

Re: Efficient Way To Do "Weighted" Random Generation?

Postby Neosoft Support » Mon Jan 26, 2015 11:29 am

You could probably use that JavaScript example to create a NeoBook Function to generated weighted list of random items.
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5602
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 3 guests

cron