简体   繁体   English

如何用PHP生成一个随机数?

[英]how to generate a random number with PHP?

I have a game built in PHP and javascript that allows users to spin a bottle around a circular board. 我有一个使用PHP和javascript构建的游戏,该游戏允许用户在圆形板上旋转瓶子。 I'm including a snippet of code from the php file that interprets the rewards users get when landing on a certain section. 我包括了php文件中的一段代码,这些代码解释了用户登陆某个特定部分时获得的奖励。 I'm trying to edit the '5 points' message part and change it so that it awards a random number of points between 1 and 50. This is more of a syntax thing, because I tried putting in 我正在尝试编辑“ 5分”消息部分并对其进行更改,以便它奖励介于1到50之间的随机数。这更多是一种语法问题,因为我尝试放入

45 => array(
    'message' => '5 Points',
    'callback' => array('point_add', array rand(1,50))
),

but that didn't work. 但这没用。 What is the correct syntax? 正确的语法是什么?

SpinBubble::$rewards = array(
0 => array(
    'message' => 'MINI Cooper Sweepstakes Entry',
    'callback' => array('sweepstakes_entry', array('cooper'))
),
15 => array(
    'message' => 'Spin Again',
    'callback' => array('credit_add', array(1))
),
30 => array(
    'message' => 'Designated Driver',
),
45 => array(
    'message' => '5 Points',
    'callback' => array('point_add', array(5))
),

Try this 尝试这个

45 => array(
    'message' => '5 Points',
    'callback' => array('point_add', array(mt_rand(1, 50)))
),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM