微信红包发红包
2015-02-27 14:39
253 查看
<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>
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>
相关文章推荐
- 微信红包算法-php代码
- 从微信红包能学到什么产品方法?
- 微信是靠什么扛住了10亿个红包?
- 一步一步实现iOS微信自动抢红包(非越狱)
- 一步一步实现iOS微信自己主动抢红包(非越狱)
- 微信红包发放注意事项
- 微信抢红包ASP.NET代码轻松实现
- 春晚微信红包,是怎么扛住一百亿次请求的
- Android QQ微信抢红包apk的实现
- AccessibilityService之微信抢红包辅助功能实现
- 微信抢红包辅助工具 AccessibilityService
- 教你一步步实现Android微信自动抢红包
- Canvas模仿微信红包照片
- 如何不越狱使用微信自动抢红包插件。
- 如何在电脑上抢微信红包
- 微信红包(2016腾讯校招笔试题)
- 牛客网----2016腾讯,,微信红包
- 算法与数据结构——算法题 21:微信红包(2016腾讯校招笔试题) ? 待解决