在教堂

时间:2017-08-16 00:38:31

标签: chapel

这是我的设置。在曲棍球比赛中,球员形成了"线"它们同时在冰上。 A"前进"线是左翼,中翼和右翼的三重奏。 A" D" line是一对Left D和Right D.在啤酒联盟中,你通常穿着13名滑冰者= 3条前锋线,2条D线加上一个守门员。

假设我有20个人想玩。我想用13个随机滑手构建线条。我必须保留他们的名字和球衣号码。我想知道这是否是Chapel Domains的工作。例如,像

这样的东西
var player_ids: domain(1) = {1..20}
var jerseys [player_ids] = [71, 99, 97, ...]
var names [player_ids] = ['Alice', 'Bonobo', 'Changarakoo'...]

这是一个简单的想法,但现在我想

1. Pick three random players and assign them to Line 1 F
2. Pick three from the remainders and assign the to Line 2 F
...
n-1: Use the player ids to create an indicator matrix (details aren't important)
n: WIN!

n-1的要点是我必须能够在最后引用玩家ID和球衣号码。

Chapel的正确模式是什么?

2 个答案:

答案 0 :(得分:2)

啤酒曲棍球队教练
可以使用这个概念
( live >>> online ) ( sure, numbers will vary, no fixed RNG-seed was set )

让我们更深入地了解这个过程。随机选择是故事中数学上更难的部分(合规性会使滑冰场外的领域的问题更加复杂,而不是教练本人(参见下文))。

所以,让我们接受团队设置是一个静态地图,玩家的序号映射到F_line{1..3,1..3}, D_line{1..2,1..2}, G, Rest{1..7}

use Random;
var              aRandomTEAM = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ]; // a known, contiguous ENUM of <anonymised_HASH_ID#s>
    permutation( aRandomTEAM );                                                                           // a known, static MAP of aRandomTEAM -> F_line{1..3}, D_line1{1..2}, G, Rest
for                          id in {1..13}{
    writeln(                   "            a Static MAP position of TEAM[",
                             id, "]: will be played by anonymised_HASH_ID#( ",
                 aRandomTEAM[id],                                         " )"
             );
    }

对于人类可读的检查,这会产生:

a Static MAP position of TEAM[1]: will be played by anonymised_HASH_ID#( 20 )
a Static MAP position of TEAM[2]: will be played by anonymised_HASH_ID#( 5 )
a Static MAP position of TEAM[3]: will be played by anonymised_HASH_ID#( 11 )
a Static MAP position of TEAM[4]: will be played by anonymised_HASH_ID#( 4 )
a Static MAP position of TEAM[5]: will be played by anonymised_HASH_ID#( 15 )
a Static MAP position of TEAM[6]: will be played by anonymised_HASH_ID#( 7 )
a Static MAP position of TEAM[7]: will be played by anonymised_HASH_ID#( 16 )
a Static MAP position of TEAM[8]: will be played by anonymised_HASH_ID#( 12 )
a Static MAP position of TEAM[9]: will be played by anonymised_HASH_ID#( 8 )
a Static MAP position of TEAM[10]: will be played by anonymised_HASH_ID#( 18 )
a Static MAP position of TEAM[11]: will be played by anonymised_HASH_ID#( 19 )
a Static MAP position of TEAM[12]: will be played by anonymised_HASH_ID#( 17 )
a Static MAP position of TEAM[13]: will be played by anonymised_HASH_ID#( 3 )
hovever,机器可读的后处理可以将这些映射到请求的数组,保持敏感的个人详细信息安全和分离,使GUUID#-reference链接到名称和所有其他详细信息安全。参照完整性既便宜又安全,并且从(有意)连续的序数到代理匿名HashTable的静态唯一关联映射的实现是微不足道的(参考不透明的域和数组可能的进一步灵感)。

法律警告:

如果在受监管的域中使用随机化,应该采取适当的谨慎措施,其中必须记录合规性并且执行和验证方法的稳健性的正面证据。

文档可能会在一些法律要求严格的领域中提供有关使用当前随机化实施的已知风险的更多详细信息:

  

置换线性同余随机数发生器

     

该模块提供PCG随机数生成例程。参见http://www.pcg-random.org/和论文,PCG:M.E. O'Neill为随机数生成提供的一系列简单快速,节省空间的统计优良算法。

特别值得关注的是一些已知的潜在限制,例如:

  

注意

     

对于整数,此类使用策略生成特定范围内的值,该策略未经过严格研究并可能存在统计问题。

     

对于实数,此类通过计算[0,1]中的随机值并缩放和移位该值,在[max,min]中生成随机值。请注意,并非所有可能的间隔[min,max]中的浮点值都可以这种方式构建。

此类备注应始终引起合规官的适当关注,以便仔细预先验证在其预期(受监管)问题域强制性实践和受控环境要求中使用的可行性。

答案 1 :(得分:2)

这是我的建议。为了吸引没有替换的玩家,我在概念上想到了洗牌一副牌 - 每张牌都有一个玩家的名字。因此,此代码使用Random.shuffle

use Random;

var player_ids = {1..20};
// jersey number, name are simply keyed off off player_id

// Generate an array of player IDs
var ids_array = [i in player_ids] i;

// Randomly shuffle player IDs
shuffle(ids_array);

// Now select from the shuffled IDs the players for the game.

var cur = 1;
getLine(cur, "Forward1", 3, ids_array);
getLine(cur, "Forward2", 3, ids_array);
getLine(cur, "Forward3", 3, ids_array);
getLine(cur, "D1", 2, ids_array);
getLine(cur, "D2", 2, ids_array);
getLine(cur, "Goalie", 1, ids_array);

proc getLine(ref curIndex, lineName, playersNeeded, ids_array) {
  writeln("Line ", lineName, ":");
  for i in 1..playersNeeded {
    writeln("  player ", ids_array[curIndex]); // would use name & jersey..
    curIndex += 1;
  }
}