Get a random subset from a set in F#

Posted by Cay on Stack Overflow See other posts from Stack Overflow or by Cay
Published on 2009-07-14T07:29:13Z Indexed on 2010/05/02 20:48 UTC
Read the original article Hit count: 224

Filed under:
|
|

I am trying to think of an elegant way of getting a random subset from a set in F#

Any thoughts on this?

Perhaps this would work: say we have a set of 2x elements and we need to pick a subset of y elements. Then if we could generate an x sized bit random number that contains exactly y 2n powers we effectively have a random mask with y holes in it. We could keep generating new random numbers until we get the first one satisfying this constraint but is there a better way?

© Stack Overflow or respective owner

Related posts about F#

Related posts about random