zoukankan      html  css  js  c++  java
  • 微信小程序 取随机数

     第一思路

    如:现在要从50<  、 =<100内取一个随机数: 

    ran.Next(1,50)生成的是1-50的随机数+50

    结束

     第二思路

    Math.random()的取值范围是:

    0<=Math.random()<1  随机小数

    Math.floor(X) =X的整数位
    例如
    Math.floor(6.999)  ===  6
    Math.floor(39.001)   ===  39
    Math.floor(8)   ===  8

    应用实例:

    Math.random()和Math.floor(X) 结合起来就可以获得一个你想要的范围内的整数。

    如:现在要从50<=  、 <100内取一个随机数:

    Math.random()*50  //这样我们就能得到一个 >=0 且 <50的随机小数

    加50:Math.random()*50 + 50    //现在这个数就 >=50 且 <100

    再使用Math.floor(Math.random()*50 + 50)取整

    结束

  • 相关阅读:
    POJ 1936 All in All
    POJ 2305 Basic remains
    POJ 2081 Recaman's Sequence
    MFC MDI 窗口函数执行顺序
    decompose
    不新建一个文档
    code mistake
    ...
    paper
    stereo
  • 原文地址:https://www.cnblogs.com/QZBOY/p/10373088.html
Copyright © 2011-2022 走看看