Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #27879
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <d@davea.name> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.022 |
| X-Spam-Evidence | '*H*': 0.96; '*S*': 0.00; 'algorithm': 0.03; 'needed,': 0.05; 'sufficient': 0.05; 'exception.': 0.07; 'empty,': 0.09; 'length.': 0.09; 'throw': 0.09; 'cc:addr:python-list': 0.10; 'assignment?': 0.16; 'statement.': 0.16; 'wrote:': 0.17; 'items.': 0.17; 'code.': 0.20; 'respective': 0.20; 'all,': 0.21; 'meant': 0.21; "i'd": 0.22; 'cc:2**0': 0.23; 'specified': 0.23; 'random': 0.24; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'looks': 0.26; 'done.': 0.27; "doesn't": 0.28; 'actual': 0.28; 'decide': 0.28; 'factor': 0.29; 'probability': 0.29; 'source': 0.29; 'code': 0.31; 'problem': 0.33; 'members.': 0.33; 'hi,': 0.33; 'requirements': 0.33; 'list': 0.35; 'lists.': 0.35; 'so,': 0.35; 'pm,': 0.35; 'similar': 0.35; 'there': 0.35; 'add': 0.36; "wasn't": 0.36; 'item': 0.37; 'far': 0.37; 'subject:: ': 0.38; 'growing': 0.38; 'received:192': 0.39; 'easily': 0.39; 'received:192.168': 0.40; 'your': 0.60; 'remove': 0.61; 'repeat': 0.62; 'times': 0.63; 'more': 0.63; 'choose': 0.65; 'header:Reply- To:1': 0.68; 'fact,': 0.69; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'goal': 0.74; '19%': 0.84; "it'd": 0.84; 'received:74.208.4.194': 0.84; 'running,': 0.84; 'items,': 0.91 |
| Date | Sat, 25 Aug 2012 12:37:50 -0400 |
| From | Dave Angel <d@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 |
| MIME-Version | 1.0 |
| To | 月忧茗 <yueyoum@gmail.com> |
| Subject | Re: Probability Algorithm |
| References | <CALZWPGh9ng4NoTRB+h0gLpNhEzJoyg+JGXOUjy=TPgqznh7HzQ@mail.gmail.com> |
| In-Reply-To | <CALZWPGh9ng4NoTRB+h0gLpNhEzJoyg+JGXOUjy=TPgqznh7HzQ@mail.gmail.com> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| X-Provags-ID | V02:K0:Hngi0EFIVtrOIHHYUSJaPclIIADISxdSrYW3DNbHRX6 M9ULhnGy0M3LlgBm/A3naXv43HImAkeq8zp/xFD0u/C+dHClOp CqoatGwG7DQB9+1POd34d66i8os+8upDHb3SYcrDP1cJg3NwJj sdyP10DwkSLWL+3/F+7y1gxQrbw9pZNv4NRTk9Cf3BP7+aDhBh bci2HIAgefJvYwD5jh6FfefAO2s+xOVGSvGxc9F7w9GkRCIb+a 9BC5vHnPZNjTWwxBdnD4daQbojmEP0/VdFeObvA04qnsgnK/iW KPFWd3js3USGNx6HuhUVQrukYx1+KbKI+/YUuJhXtT6z7vsFw= = |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| Reply-To | d@davea.name |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3808.1345912705.4697.python-list@python.org> (permalink) |
| Lines | 58 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1345912706 news.xs4all.nl 6883 [2001:888:2000:d::a6]:54009 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:27879 |
Show key headers only | View raw
On 08/25/2012 12:03 PM, 月忧茗 wrote: > Hi, All, > > I have a problem of probability algorithm > > > The goal is obtain a list which contains three items. as the *FinalList* > > There has Four source lists. * > ALIST, BLIST, CLIST, DLIST > > There are all Unknown length. They contains unique elements* > ( In fact, there are all empty at the program beginning, when running, > there growing ) > > Choose items form this source lists. pick up random items to generate the > FinalList > Ensure The Following Requirements > > In the FinalList, > probability of ALIST's item appeared is 43% > probability of BLIST's item appeared is 37% > probability of CLIST's item appeared is 19% > probability of DLIST's item appeared is 1% > > Would you like to tell us the actual assignment? This looks like it's paraphrased. if you have 3 items, each coming from one of four lists, the four probabilities have to add up to much more than 100%. Perhaps what you meant was that each of the three items had those probabilities of coming from the respective lists. Then it'd add up to 100%. Your code is far more complex than needed, and as you observed, doesn't work if each list doesn't have sufficient members. I'd simply pick a random number from 0 to 99, see if it's less than 43 and if so, use ALIST. Else if it's less than 80, use BLIST. else if it's less than 99, use CLIST. Else DLIST. Then do that 2 more times and you're done. Don't forget to factor the problem into functions, so you can easily repeat similar code. If a list is picked, and it's empty, throw an exception. Or wait till the missing item arrives. And you have to decide whether to remove the selected items from the respective lists. That wasn't specified in the problem statement. -- DaveA
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Probability Algorithm Dave Angel <d@davea.name> - 2012-08-25 12:37 -0400 Re: Probability Algorithm Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-26 03:47 +0000
csiph-web