English 中文(简体)
选编清单内容的随机组合,因此在一个以上甄选中不存在任何名单要素(SQL)。
原标题:Select random combinations of list elements such that no list element is present in more than one selection (SQL)

I m running a bit out of ideas how to realize a small project.

What I have:
- a list of users including their ID and name

What I want to achieve:
- I want to combine each user on this list with another user such that no user is assigned to more than one user and no user is assigned to herself. - The combination has to be random and has to take past combinations into account

My idea so far:
- I have this information:

User (A,B,C,D) (the actual number of users ranges between 50 and 400)
Possible combinations: (A-B,A-C,A-D,B-C,B-D,C-D)
Random draw(1): (A-B, C-D)
Random draw(2): (A-D, B-C)
Random draw(3): (A-C, B-D)

  • I was able to get all possible combinations using a join of the user table with itself.
  • I guess I can take previous draws into account by storing the draws in a separate table and limit the possible combinations to those that are not in this special table.

What I can t do:
- I don t know how to randomly draw from the list of possible combinations such that every user is part of only one combination per draw (e.g. A-B,A-D in the same draw is not allowed)
- I try to use sql or a bit php for this (maybe javascript)

感谢任何帮助。

问题回答

容易的解决办法:

为每张奶制品设立一个临时桌。 用户名册上抽空了随机数目的单行,从1行到空行的数量。

简便解决办法2:

考虑到N用户。 每个用户的随机数量从1个减少到1个(随机从1个移至1个)。 用户从N/2+1到N。

The solution is the problem "Bergr (s) table", see Wikipedia: http://en.wikipedia.org/wiki/Round-robin_tournament.

最新的(最佳)解决办法来自Frončeka教授(Dalibor Froncek,美国明尼苏达大学教授)。

关于习俗解决办法,见解决办法表第2号。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签