How about something like:
r=:10#0
pick=:3 : 0
z=.+/\r=:>:r
i=.z I.?>:{:z
r=:0 i}r
i
)
where r is a list of things to pick randomly. pick gets one item from the
list. The chosen item may still be selected the next time but less likely.
If you don't want to pick the last one the next time pick is called, set it
to _1 instead of 0.
2010/1/16 Björn Helgason <[email protected]>
> The idea is to pick items at random from a set.
>
> Once an item has been picked it should have a chance to be picked
> again but a little bit less likely.
>
> I am not sure how to best do this but I have a simple example here
> to demonstrate what I mean.
>
>
>
> a=.i.10
> b=.10#10
> c=.b#a
> d=.+/b
> e=.?d
> f=.e{c
> SEL_sel_=.i.0
> SEL_sel_=.SEL_sel_,f
> b=.b- f=a
> c=.b#a
> d=.+/b
> e=.?d
> f=.e{c
> SEL_sel_=.SEL_sel_,f
> b=.b- f=a
> c=.b#a
> d=.+/b
> e=.?d
> f=.e{c
> SEL_sel_=.SEL_sel_,f
> b=.b- f=a
> c=.b#a
> d=.+/b
> e=.?d
> f=.e{c
> SEL_sel_=.SEL_sel_,f
> SEL_sel_
> b
>
> SEL_sel_ collects all the picked items
> b gives how many of each items are of each
>
>
>
> --
> Björn Helgason, Verkfræðingur
> Fornustekkum II
> 781 Hornafirði
> Po Box 127,801 Selfoss ,
> t-póst: [email protected]
> gsm: +3546985532
> sími: +3544781286
> http://groups.google.com/group/J-Programming
>
>
> Tæknikunnátta höndlar hið flókna, sköpunargáfa er meistari einfaldleikans
>
> góður kennari getur stigið á tær án þess að glansinn fari af skónum
> /|_ .-----------------------------------.
> ,' .\ / | Með léttri lund verður |
> ,--' _,' | Dagurinn í dag |
> / / | Enn betri en gærdagurinn |
> ( -. | `-----------------------------------'
> | ) | (\_ _/)
> (`-. '--.) (='.'=) ♖♘♗♕♔♙
> `. )----' (")_(") ☃☠
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm