dtgj8529 2017-12-28 21:37
浏览 25

创建一个医学研究的网站,需要随机但均匀地将用户分成两组

I have this problem im trying to figure out. At first i thought about seperating users just by their user id by odds and evens. But my client says it needs to be a little bit more random then that.

if($user_id % 2 == 0) {

        $u->add_role( 'control' );
    }else{
        $u->add_role( 'study' );
    }

Users need to be placed into a control group, and a study group, out of 10 there need to be 5 in each, out of 100, 50 etc. But it apperantly something like 1 3 5 7 and 9 cant go in one while 2 4 6 8 10 go in the other. It should be more like

1 3 5 6 7 go in one 2 4 8 9 10 go in the other.

Im having trouble figuring out how to do that in a way that scales

  • 写回答

1条回答 默认 最新

  • douzi0609 2017-12-28 21:43
    关注

    Why don't you make a list of all the users. Then randomly choose an index to select a user, assign it the group and then remove it from the list. Just alternate the type of group as you go. When the list is empty, you've assigned all the users.

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line