esc0rp 发表于 2024-11-1 10:11:20

「按键精灵安卓版」脚本怎么才可用好随机数这个功能


    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">大众</span>好,我是公众号3分钟学堂的郭立员,今天继续按键精灵安卓版教程的讲解,这一期说一下脚本中随机数这个功能。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">随机操作<span style="color: black;">能够</span>想到的有<span style="color: black;">非常多</span>,<span style="color: black;">例如</span>说随机时间、随机字符、随机点击坐标、随机读取文本,随机话术、随机滑动等等。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">虽然种类<span style="color: black;">非常多</span>,<span style="color: black;">然则</span>核心<span style="color: black;">仅有</span>一个<span style="color: black;">便是</span>“</span><span style="color: black;">随机数</span>”。所有随机操作都是基于随机数演变而来的。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">那样</span>在讲随机操作之前,<span style="color: black;">咱们</span>先来把随机数讲明白了。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">(一)随机数的介绍:</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">初学按键随机数时会有<span style="color: black;">这般</span>一个公式:(官方例子有错误,这么<span style="color: black;">数年</span>都没改过来)</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">随机数=Int((最大值-最小值+1)*Rnd()+最小值)</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">咱们</span>每次<span style="color: black;">运用</span>时都会套用这个公式,<span style="color: black;">例如</span>命令介绍中的获取2到6的随机数,会写成:</span></span></p>dim MyValue = <span style="color: black;">Int</span>(((<span style="color: black;">6</span>-<span style="color: black;">2</span>+<span style="color: black;">1</span>) * Rnd()) + <span style="color: black;">2</span>)<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">当<span style="color: black;">咱们</span>仔细分析的时候,会<span style="color: black;">发掘</span>起到随机<span style="color: black;">功效</span>的是Rnd( )这个命令,<span style="color: black;">这儿</span><span style="color: black;">咱们</span>单独调试输出这个命令,看一下结果。</span></span></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/c535b6eb2d73432a8fdf7f5fd6e99409~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1729612934&amp;x-signature=CD6NLN4SjtmDdUxPB7vSGdBXhho%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">Rnd( )的范围0-0.99999999999999,最大值无限接近1的。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">假如<span style="color: black;">咱们</span>用5去乘以Rnd(),<span style="color: black;">那样</span>随机范围<span style="color: black;">便是</span>0到4.99999999999999,最大值非常接近5,(比5小一点点)。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">再<span style="color: black;">来讲</span>说一下int命令:取整数,比方说:</span></span></p>cint(4.99999999999999)=4<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">针对</span>小数点后面的数会<span style="color: black;">所有</span>去掉,只<span style="color: black;">保存</span>整数。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">我平时在写随机数的时候会在脑子里简单算一下,<span style="color: black;">例如</span></span></span></p>dim MyValue=<span style="color: black;">Int</span>(((<span style="color: black;">6</span>-<span style="color: black;">2</span>+<span style="color: black;">1</span>)*Rnd())+<span style="color: black;">2</span>)<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">6-2+1=5,在代码中我就直接写5,<span style="color: black;">而后</span>就<span style="color: black;">能够</span>简化<span style="color: black;">非常多</span>括号。</span></span></p>dim MyValue=<span style="color: black;">Int</span>(<span style="color: black;">5</span>*rnd())+<span style="color: black;">2</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">这儿</span>面5是随机范围数组的个数,2到6,细数一下<span style="color: black;">便是</span>23456这5个数字。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">2是随机数<span style="color: black;">起始</span>的数字。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">int(随机个数*rnd())+<span style="color: black;">初始</span>数字</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">咱们</span>在<span style="color: black;">运用</span>随机数的时候不要不舍得计算啊,像6-2+1这种加减法,直接算出结果啊,至于最大数-最小数+1这个过程在心里想一下就行了。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">(二)随机操作的介绍</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">随机操作是两部分:</span><span style="color: black;">随机数和数字<span style="color: black;">掌控</span>操作</span>。随机数<span style="color: black;">已然</span>讲过了,<span style="color: black;">那样</span>数字<span style="color: black;">掌控</span>操作是什么呢?</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">本身是<span style="color: black;">无</span>这个概念,<span style="color: black;">这儿</span>我就随便起个名,其实<span style="color: black;">便是</span>数字<span style="color: black;">做为</span>命令的重要参数<span style="color: black;">罢了</span>。当数字是随机数,自然就会影响到命令操作的随机执行了。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">总结一下<span style="color: black;">便是</span></span><span style="color: black;">只要命令能用数字<span style="color: black;">做为</span>参数的,都<span style="color: black;">能够</span>随机执行。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">下面我用实例演示给<span style="color: black;">大众</span>:为了方便<span style="color: black;">大众</span>查看,代码中的变量我<span style="color: black;">尽可能</span>以中文命名。</p>

    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">①随机读取文本:随机数<span style="color: black;">做为</span>行号</span></span></p>dim 随机行号=<span style="color: black;">Int</span>(<span style="color: black;">5</span>*rnd())+<span style="color: black;">2</span>
    TracePrint file.readline(<span style="color: black;">"/sdcard/pictures/1.txt"</span>,随机行号)<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">②随机时间:随机数<span style="color: black;">做为</span>delay的参数</span></span></p><span style="color: black;">dim</span> <span style="color: black;">随机时间=Int(5*rnd())+2</span>
    <span style="color: black;">Delay</span> <span style="color: black;">随机时间*1000</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">思虑</span>到delay参数的单位是毫秒,<span style="color: black;">因此</span>乘以1000变成秒。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">③随机点击:随机数<span style="color: black;">做为</span>点击的坐标</span></span></p><span style="color: black;">dim</span> <span style="color: black;">随机x=Int(5*rnd())+2</span>
    <span style="color: black;">dim</span> <span style="color: black;">随机y=Int(5*rnd())+2</span>
    <span style="color: black;">Tap</span> <span style="color: black;">随机x,随机y</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">④随机字母:随机数<span style="color: black;">做为</span>字母的位置编号</span></span></p><span style="color: black;">Dim</span> <span style="color: black;">字母="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"</span>
    <span style="color: black;">Dim</span> <span style="color: black;">随机数=int(52*rnd())+1</span>
    <span style="color: black;">TracePrint</span> <span style="color: black;">mid(字母,随机数,1)</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">⑤随机多个字母(字符串):循环执行随机字母</span></span></p><span style="color: black;">Dim</span> <span style="color: black;">字母="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"</span>
    <span style="color: black;">Dim</span> <span style="color: black;">序列=""</span>
    <span style="color: black;">For</span> <span style="color: black;">5</span>
    <span style="color: black;">Dim</span> <span style="color: black;">随机数=int(52*rnd())+1</span>
    <span style="color: black;">序列</span>=<span style="color: black;">序列&amp;mid(字母,随机数,1)</span>
    <span style="color: black;">Next</span>
    <span style="color: black;">TracePrint</span> <span style="color: black;">序列</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">⑥随机读取界面输入框:随机数作为输入框的序号</span></span></p>Dim 随机序号=<span style="color: black;">Int</span>(<span style="color: black;">3</span>*rnd())+<span style="color: black;">1</span>
    TracePrint ReadUIConfig(<span style="color: black;">"输入框"</span>&amp;随机序号)<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">⑦随机数<span style="color: black;">做为</span>数组下标</span></span></p>Dim 数组=<span style="color: black;">array</span>(<span style="color: black;">"a"</span>,<span style="color: black;">"b"</span>,<span style="color: black;">"c"</span>)
    Dim 随机下标=<span style="color: black;">int</span>(<span style="color: black;">3</span>*rnd())
    TracePrint 数组(随机下标)<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">⑧随机执行任务:随机数<span style="color: black;">做为</span>判断<span style="color: black;">要求</span></span></span></p><span style="color: black;">Dim</span> <span style="color: black;">随机数=int(3*rnd())</span>
    <span style="color: black;">If</span> <span style="color: black;">随机数 = 0 Then </span>
    <span style="color: black;">TracePrint</span> <span style="color: black;">"任务1"</span>
    <span style="color: black;">ElseIf</span> <span style="color: black;">随机数 = 1 Then</span>
    <span style="color: black;">TracePrint</span> <span style="color: black;">"任务2"</span>
    <span style="color: black;">ElseIf</span> <span style="color: black;">随机数 = 2 Then</span>
    <span style="color: black;">TracePrint</span> <span style="color: black;">"任务3"</span>
    <span style="color: black;">End</span> <span style="color: black;">If</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">要求</span><span style="color: black;">选取</span>Select Case和这个<span style="color: black;">同样</span>,<span style="color: black;">这儿</span>就省略了。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">⑨随机滑动:随机数<span style="color: black;">做为</span>滑动坐标的变化值</span></span></p><span style="color: black;">Dim</span> <span style="color: black;">随机数=int(10*rnd())</span>
    <span style="color: black;">Swipe</span> <span style="color: black;">200,300,200+随机数,500,1000</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">swipe这个命令有5个数字参数,<span style="color: black;">每一个</span>参数都<span style="color: black;">能够</span>用随机数。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">⑩随机不重复,正常随机是不会<span style="color: black;">显现</span>这种<span style="color: black;">状况</span>的,之前写过两篇<span style="color: black;">文案</span>教程了,<span style="color: black;">这儿</span>直接放链接,自己看吧</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">随机数不重复排序(不限个数)</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">问题解答:<span style="color: black;">怎样</span>将0-9随机<span style="color: black;">摆列</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">平常</span>的随机操作<span style="color: black;">便是</span>这些,<span style="color: black;">大众</span><span style="color: black;">能够</span>想想还有<span style="color: black;">那些</span>命令是有数字参数的。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">例如</span>,mid命令、instr命令、for循环、找图命令还有挺多的,当你想随机的时候,只要用随机数替换命令中的数字参数就<span style="color: black;">能够</span>实现随机操作了。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">关于随机操作<span style="color: black;">大众</span>活学活用,只要和数字能够沾边的基本都<span style="color: black;">能够</span>随机。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">内容就这些,<span style="color: black;">爱好</span>的<span style="color: black;">伴侣</span><span style="color: black;">能够</span>留言、点赞。</span></span></p>




页: [1]
查看完整版本: 「按键精灵安卓版」脚本怎么才可用好随机数这个功能