Generating random values with a selection variable

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

Attachment: selection_var.xml (2.13 KB)

Thanks Chris. It works perfectly.

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

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

Thanks Chris