代码如下:
<?php
/**
*
抽奖
*
@param
int
$total
*/
function
getReward($total=1000)
{
$win1
=
floor((0.12*$total)/100)
$win2
=
floor((3*$total)/100)
$win3
=
floor((12*$total)/100)
$other
=
$total-$win1-$win2-$win3
$return
=
array()
for
($i=0$i<$win1$i++)
{
$return[]
=
1
}
for
($j=0$j<$win2$j++)
{
$return[]
=
2
}
for
($m=0$m<$win3$m++)
{
$return[]
=
3
}
for
($n=0$n<$other$n++)
{
$return[]
=
'谢谢惠顾'
}
shuffle($return)
return
$return[array_rand($return)]
}
$data
=
getReward()
echo
$data
?>
import java.awt.EventQueueimport java.awt.TextArea
import java.awt.TextField
import java.awt.event.ActionEvent
import java.awt.event.ActionListener
import java.util.Random
import javax.swing.JButton
import javax.swing.JFrame
import javax.swing.JLabel
import javax.swing.JPanel
import javax.swing.JTextArea
import javax.swing.JTextField
import javax.swing.border.EmptyBorder
public class LuckySelect extends JFrame {
private JPanel contentPane
private JTextField textFieldA
private JTextField textFieldB
private JTextField textFieldC
private 闷橘TextField textField
private JTextField textFieldResult
private JTextArea textArea
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
LuckySelect frame = new LuckySelect()
frame.setVisible(true)
} catch (Exception e) {
e.printStackTrace()
}
}
})
}
/**
* Create the frame.
*/
public LuckySelect() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
setBounds(100, 100, 450, 251)
contentPane = new JPanel()
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5))
contentPane.setLayout(null)
setContentPane(contentPane)
JLabel lblA = new JLabel("A")
lblA.setBounds(10, 128, 54, 15)
contentPane.add(lblA)
JLabel lblB = new JLabel("B")
lblB.setBounds(124, 128, 缓纳54, 15)
contentPane.add(lblB)
JLabel lblC = new JLabel("C")
lblC.setBounds(254, 128, 54, 15)
contentPane.add(lblC)
textFieldA 蚂哪团= new JTextField()
textFieldA.setBounds(30, 125, 66, 21)
contentPane.add(textFieldA)
textFieldA.setColumns(10)
textFieldB = new JTextField()
textFieldB.setColumns(10)
textFieldB.setBounds(149, 125, 66, 21)
contentPane.add(textFieldB)
textFieldC = new JTextField()
textFieldC.setColumns(10)
textFieldC.setBounds(264, 125, 66, 21)
contentPane.add(textFieldC)
textField = new TextField()
textField.setBounds(98, 167, 157, 21)
contentPane.add(textField)
textField.setColumns(10)
textFieldResult = new JTextField()
textFieldResult.setBounds(280, 167, 66, 21)
contentPane.add(textFieldResult)
textFieldResult.setColumns(10)
textFieldA.setText("10")
textFieldB.setText("10")
textFieldC.setText("10")
JButton button = new JButton("\u62BD\u5956")
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
select()
}
})
button.setBounds(0, 166, 93, 23)
contentPane.add(button)
textArea = new JTextArea()
textArea.setBounds(30, 31, 306, 83)
contentPane.add(textArea)
}
protected void select() {
// TODO Auto-generated method stub
int aNum = Integer.decode(textFieldA.getText())
int bNum = Integer.decode(textFieldB.getText())
int cNum = Integer.decode(textFieldB.getText())
Random r = new Random()
int random = r.nextInt(aNum + bNum + cNum)
if(random <= aNum){
textFieldA.setText(Integer.toString(Integer.decode(textFieldA.getText()) - 1))
textArea.append(Integer.toString(random) + "抽中了A\n")
}else if(random <= aNum + bNum){
textFieldB.setText(Integer.toString(Integer.decode(textFieldB.getText()) - 1))
textArea.append(Integer.toString(random) + "抽中了B\n")
}else if(random <= aNum + bNum + cNum){
textFieldC.setText(Integer.toString(Integer.decode(textFieldC.getText()) - 1))
textArea.append(Integer.toString(random) + "抽中了C\n")
}
}
}
制作抽奖小程序流程如下:
工具:人人秀2022、机械革命S3 Pro、Windows10。
1、进入首页右上方的工作台,选择新建-互动模块,在d出窗口选择弯游抽奖。
2、进入编辑模板,开始基本设置,包括活动名称、活动时间、活动类型、活动规则等。
3、奖品设置中可以添加奖品,选择相应的奖品的中奖个数以及中奖率,奖品类型有实物、红包、优惠券、积分等多种选择。
4、高级设置中设置抽奖规则、抽奖埋漏销次数等等。
5、样式设置中可以直接使用,也可以根据自己的喜好,做一些背景和按钮的改搜陆动。设置以后就可以直接发布分享了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)