小程序---365笔记第14天---生成10个随机数

将数字100拆分为10个随机数;

  <script type="text/javascript">
    let redpackage = function(){
    let sum =100;
    let money;
    for(let i =0;i<15;i++){
	    if(i===15){
		    money=sum;
	    }else{
		    money=(Math.random()*sum).toFixed(2);
	    }
	    sum=sum-money;
	
	    console.log("第"+i+"位"+money+"元")
	    console.log(sum);
    }
} 
</script>

打印出来的结果;

    redpackage();
    test.html:30 第0位38.65元
    test.html:31 61.35
    test.html:30 第1位41.91元
    test.html:31 19.440000000000005
    test.html:30 第2位15.38元
    test.html:31 4.060000000000004
    test.html:30 第3位3.25元
    test.html:31 0.810000000000004
    test.html:30 第4位0.65元
    test.html:31 0.16000000000000403
    test.html:30 第5位0.03元
    test.html:31 0.13000000000000403
    test.html:30 第6位0.02元
    test.html:31 0.11000000000000403
    test.html:30 第7位0.03元
    test.html:31 0.08000000000000403
    test.html:30 第8位0.03元
    test.html:31 0.05000000000000403
    test.html:30 第9位0.01元
    test.html:31 0.040000000000004025
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值