playMaker

Author Topic: Weighted Randomness?  (Read 2476 times)

JennaReanne

  • Junior Playmaker
  • **
  • Posts: 57
    • Little Worlds Interactive
Weighted Randomness?
« on: May 14, 2013, 10:16:30 AM »
Hello all,
What is the most efficient way to choose between a few options in a way that is weighted?  For example, I want to pick between the numbers 2, 3 and 4.  However, I want there to be a 20% chance of picking 2, 60% chance of picking 3, and 20% chance of picking 4.  I've thought of a few different ways of doing this:

1. Use "Send Random Event" to pick one of these three options, fire it off to one of three States which sets the variable value.  This seems inefficient because it requires so many states.

2. Use Arraymaker to create an array that looks something like this: 2, 2, 3, 3, 3, 3, 3, 3, 4, 4.  Randomly choose a value out of it.

Is there anything else that might accomplish this elegantly?

Thank you,
Jenna

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Weighted Randomness?
« Reply #1 on: May 14, 2013, 12:54:22 PM »
Hi,

 Actually PlayMaker has a built in function internally used for the following action "SendRandomEvent".

this action accepts weights, so you could use this action to trigger different states.

would that do in your case? or do you really need to just get the integer? I can easily make such action similar to "SendRandomEvent" but where instead of events you have numbers or strings or whatever.

bye,

 Jean

JennaReanne

  • Junior Playmaker
  • **
  • Posts: 57
    • Little Worlds Interactive
Re: Weighted Randomness?
« Reply #2 on: May 14, 2013, 01:25:40 PM »
Hi Jean,
I don't need to trigger different states, I'm just looking to get the integer.  If you could create an action similar to SendRandomEvent that set variables instead it would be amazing - thank you so much!

All the best,
Jenna

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Weighted Randomness?
« Reply #3 on: May 14, 2013, 01:40:02 PM »

JennaReanne

  • Junior Playmaker
  • **
  • Posts: 57
    • Little Worlds Interactive
Re: Weighted Randomness?
« Reply #4 on: May 14, 2013, 04:29:29 PM »
Thank you so much!!