Generating random values with a selection variable

Christopher Stawarz's Avatar

Christopher Stawarz

22 Apr, 2011 08:56 PM

Hi Arash and Najib,

I investigated the issue we were discussing some more.

It appears that negative numbers in a selection variable's "values" list get converted to positive numbers. I don't yet see where or why this happens, but I'll figure it out and let you know.

As for Arash's original question (i.e. how to use a selection variable to draw randomly from a finite set of values), I've attached an example that demonstrates one way to do it. Here are the key points:

  • nsamples is set to the number of values in values
  • sampling_method is "samples"
  • While the number of draws is less than the number of values, you do "Next Selection" after each draw. When the number of draws equals the number of values, you do "Reset Selections".

This technique works equally well for random_with_replacement and random_without_replacement. (The example demonstrates random_without_replacement.)

There are probably other ways to do this, but this approach seems relatively straightforward to me.

Chris

  1. 1 Posted by Arash Afraz on 24 Apr, 2011 09:35 PM

    Arash Afraz's Avatar

    Thanks Chris. It works perfectly.

  2. Support Staff 2 Posted by Christopher Sta... on 25 Apr, 2011 03:53 PM

    Christopher Stawarz's Avatar

    It appears that negative numbers in a selection variable's "values" list get converted to positive numbers. I don't yet see where or why this happens, but I'll figure it out and let you know.

    I figured it out. This is happening because the library routine we use to split up the "values" list treats all punctation characters (including "-") as item delimiters. Thus "0,-1,2" is interpreted the same as "0,,1,2", and all the values end up positive.

    I've opened up a ticket for this issue. It should be easy to fix.

    Chris

  3. Christopher Stawarz closed this discussion on 25 Apr, 2011 07:28 PM.

  4. Christopher Stawarz re-opened this discussion on 03 Oct, 2012 08:17 PM

  5. Support Staff 3 Posted by Christopher Sta... on 03 Oct, 2012 08:17 PM

    Christopher Stawarz's Avatar

    Hi Arash and Najib,

    The selection variable bug that caused negative values to be converted to positive values is now fixed. As of tonight's nightly build (and the upcoming MWorks 0.5 release), you should be able to using negative values in the "values" list without any trouble.

    Cheers,
    Chris

  6. Christopher Stawarz closed this discussion on 03 Oct, 2012 08:18 PM.

  7. 4 Posted by Arash Afraz on 03 Oct, 2012 08:58 PM

    Arash Afraz's Avatar

    Thanks Chris

  8. Christopher Stawarz closed this discussion on 04 Oct, 2012 01:45 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac