duanpaxin3531 2011-07-06 19:00
浏览 47
已采纳

执行A / B拆分的最理想的跨语言方法是什么?

I'm on a project where I have to implement an A/B split in 15 or so views, in this case for PHP - we'd like to use the same math if possible for our JavaScript projects.

What is the most ideal, least verbose, least CPU-intensive way of doing this? For this project, I just need to set a variable: something like:

// In the main controller
if(rand(1, 2) == 2)
{
    $recipe = 'program';
}
else
{
    $recipe = 'standard';
}
define('RECIPE',$recipe);


// In the view
$program = (RECIPE == 'program') ? '&ProgramOfInterest=' . $program_id : '';

We have 20 or so devs here and we all have our ways - what is the best, benchmark-proven way?

  • 写回答

3条回答 默认 最新

  • doujia7779 2011-07-10 18:49
    关注

    You should use mt_rand() over rand(). It's 4x faster than rand() because mt_rand uses a Mersenne Twister over the libc random number generator which rand() uses (see php.net).

    You can then get an equivalent to mt_rand() for javascript from the php.js library.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 C# 爬虫融通金网址实时银价
  • ¥15 热敏电阻NTC,温控不同颜色的LED的亮与灭,PCB
  • ¥20 ESP32使用MicroPyhon开发,怎么获取485温湿度的值,温湿度计使用的鞋子是Modbus RTU
  • ¥50 苹果MGIE项目部署缺少emb权重
  • ¥15 采用ansys进行机翼在特定路径下的打孔过程中的受力分析
  • ¥15 单片机adb主机连接手机,usb调试密钥无法保存
  • ¥15 已知X和Y有以下关系,求X和Y的关系式
  • ¥15 net core 同时编辑怎么防止数据多保存了
  • ¥15 matlab做ba模型让其在ba和er规则下生长
  • ¥15 请问Quartus的Verilog代码怎么写?