微信红包发红包
来源:互联网 发布:上海数据交易中心 看准 编辑:程序博客网 时间:2024/04/29 02:59
<p>
x元钱分n个红包,要求每个红包钱数大于0;每个红包钱数尽量不同;最大红包钱少于x/4;以上为基本要求,附加要求:如果钱数尾数不为4或7,尾数为8越多越好!有兴趣的同事将编好的程序微信给我!有红包奖励!</p>
红包个数:<input type="text" name="count"/>
总金额:<input type="text" name="money"/>
<button id="gomoney">发红包</button>
<table id="peopleL">
</table>
<script type="text/javascript" src="./jquery-1.8.2.min.js"></script>
<script type="text/javascript">
//author:wangmao
$("#gomoney").click(function(){
var hcount=$("input[name='count']").val();
var hmoney=$("input[name='money']").val();
if(undefined!=hcount&&undefined!=hmoney){
hcount=parseInt(hcount);
hmoney=parseFloat(hmoney);
var peopleList=new Array();
if(hcount>=1&&hmoney>(hcount*0.1)){
var newcount=hcount;
for(var i=0;i<hcount;i++){
if(1==hcount||(i+1)==hcount){
peopleList[i]=hmoney.toFixed(1);
}else{
if(hcount>1){
var num=Math.random()*(hmoney/4-(0.1*newcount));
var newmoney =num.toFixed(1);
if(newmoney==0){
newmoney=0.1;
}
var nmoney=newmoney+"";
//获取随机钱数小数点前几位
var qnumber=nmoney.split(".")[0];
//如果整数列长度2位数,则使其尾数为8
if(qnumber.length>=2){
var numberlist=new Array();
for(var p=0;p<qnumber.length;p++){
var snumber=((8*getnumber(qnumber.length-p))-(parseInt(qnumber.substring(p,p+1)))*(getnumber(qnumber.length-p)));
newmoney=(parseFloat(newmoney+snumber));
}
}
var h1number=parseFloat(0.8-(parseInt(nmoney.split(".")[1])*0.1));
if((hmoney/newcount)>h1number){
newmoney=(parseFloat(newmoney+h1number));
}
var o1money=newmoney+"";
newmoney=parseFloat(o1money.substring(0,(o1money.split(".")[0].length+2)));
peopleList[i]=newmoney;
newcount=newcount-1;
hmoney=hmoney-newmoney;
}
}
}
$("#peopleL").children().remove();
for(var pobj=0;pobj<peopleList.length;pobj++){
$("#peopleL").append("<tr><td>第"+(pobj+1)+"个红包</td><td>金额为"+peopleList[pobj]+"</td></tr>");
}
}else{
alert("输入有误")
}
}else{
alert("输入有误")
}
})
function getnumber(number){
var newnumber="1";
for(var i=1;i<parseInt(number);i++){
newnumber+="0"
}
return parseInt(newnumber);
}
</script>
0 0
- 微信红包发红包
- 微信发红包算法
- 微信红包海量运营-----“海量之道2.0”(春节发红包如何保证服务器正常运行)
- 微信公众平台发红包接口
- 微信公众号发红包
- PHP微信发红包简明教程
- PHP实现微信发红包程序
- 微信给用户发红包
- 微信发红包功能的实现
- 微信发红包 PHP 实现
- 讨红包与发红包----产品设计
- 支付宝商家红包发红包步骤
- 1553: 发红包(2):红包来啦~
- 微信发红包代码,解决中文乱码问题
- 微信发红包,出现了内部错误。
- 微信发红包UITextField金额输入格式化
- 微信商户发红包和获取用户信息
- 使用微信公众号进行发红包
- CVE-2015-0235 实验记录
- Localization native development region
- 美国流媒体一瞥
- Android安卓----No Launcher activity found问题
- 笔记103--自定义ProgressBar
- 微信红包发红包
- CodeForces 343B Alternating Current
- IOS学习 断点的应用
- DAO设计模式
- JS 动态加载脚本并在下载完成后执行回调
- ubuntu安装了im-switch后系统设置中不见了语言支持
- Maven最佳实践:划分模块
- IntelliJ IDEA 常用快捷键整理
- 辛星解读UML建模中的类图