Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #49282
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Weighted choices |
| Date | 2016-07-21 16:46 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <nmqu9v$km6$1@dont-email.me> (permalink) |
R:
weighted.random.choices = function(choices, n)
{ matrix(choices, 2) -> m
sample( m[1,], n, prob=m[2,], rep=TRUE)
}
summary(factor(unlist(
weighted.random.choices(list("quarter1",0.1, "quarter2",0.1, "half",0.2),
100000))))
half quarter1 quarter2
50045 24736 25219
In ANS Forth?
--
The report card by the American Society of Civil Engineers showed the national
infrastructure a single grade above failure, a step from declining to the point
where everyday things simply stop working the way people expect them to. ---
washingtonpost.com/local/trafficandcommuting/us-infrastructure-gets-d-in-annual-report/2013/03/19/c48cb010-900b-11e2-9cfd-36d6c9b5d7ad_story.html
Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread
Weighted choices "WJ" <w_a_x_man@yahoo.com> - 2016-07-21 16:46 +0000
csiph-web