Giáo Trình How To Use AutoIt A Professional Manner part 93 ppsx

6 175 0
Giáo Trình How To Use AutoIt A Professional Manner part 93 ppsx

Đang tải... (xem toàn văn)

Thông tin tài liệu

Related Exp Example $x = Log(1000) ;returns 6.90775527898214 $y = Log10(1000) ;returns 3 ; user-defined function for common log Func Log10($x) Return Log($x) / Log(10) ;10 is the base EndFunc Function Reference Mod chia lấy phần dư. Mod ( value1, value2 ) Parameters value1 số bị chia value2 số chia Return Value Success: trả lại số Failure: trả lại -1. nếu lỗi chia cho 0. Remarks hàm có thể làm việc với cả số thực Related None. Example $n = 18 If mod($n, 2) = 0 Then MsgBox(0,"", $n & " is an even number.") Else MsgBox(0, "", $n & " is an odd number.") EndIf $x = mod(4, 7) ;$x == 4 because the divisor > dividend $y = mod(1, 3/4) ;$y == 0.25 because the divisor is a float Function Reference Random trả lại một số ngẫu nhiên. Random ( [Min [, Max [, Flag]]] ) Parameters Min giới hạn giá trị nhỏ nhất có thể đạt đc, mặc định = 0 Max giới hạn giá trị lớn nhất có thể đạt đc, mặc định = 1. Flag = 0 lấy số thực (mặc định) = 1 chỉ lấy số nguyên Return Value Success: số Failure: trả lại 0 và set @error=1 nếu tham số ko hợp lệ Remarks By default the Random function works with decimal/floating point numbers. If you want to only have integer/whole number results then set the Flag to 1. If only one argument is provided, then it is interpreted to be the Max. The result will be in the range of Min to Max INCLUSIVE when using integers (just short of Max when using floats). When using integers Max-Min must be less than 2^31. Comments based on the original source This function uses the Mersenne Twister random number generator, MT19937, written by Takuji Nishimura, Makoto Matsumoto, Shawn Cokus, Matthe Bellew and Isaku Wada. The Mersenne Twister is an algorithm for generating random numbers. It was designed with consideration of the flaws in various other generators. The period, 2 19937 -1, and the order of equidistribution, 623 dimensions, are far greater. The generator is also fast; it avoids multiplication and division, and it benefits from caches and pipelines. For more information see the inventors' web page at http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Related Int, Round, SRandom Example ;Flip of coin If Random() < 0.5 Then ; Returns a value between 0 and 1. $msg = "Heads. 50% Win" Else $msg = "Tails. 50% Loss" Endif MsgBox(0,"Coin toss", $msg ) ;Roll of a die msgBox(0, "Roll of die", "You rolled a " & Random(1, 6, 1) ) $StockPrice = 98 ;In the middle of a stock market simulation game $StockPriceChange = Random(-10, 10, 1) ; generate an integer between -10 and 10 $StockPrice = $StockPrice + $StockPriceChange If $StockPriceChange < 0 Then MsgBox(4096, "Stock Change", "Your stock dropped to $" & $StockPrice) ElseIf $StockPriceChange > 0 Then MsgBox(4096, "Stock Change", "Your stock rose to $" & $StockPrice) Else MsgBox(4096, "Stock Change", "Your stock stayed at $" & $StockPrice) Endif ;Random letter If Random() < 0.5 Then ;Capitals $Letter = Chr(Random(Asc("A"), Asc("Z"), 1)) Else ;Lower case $Letter = Chr(Random(Asc("a"), Asc("z"), 1)) Endif Function Reference . function uses the Mersenne Twister random number generator, MT1 9937 , written by Takuji Nishimura, Makoto Matsumoto, Shawn Cokus, Matthe Bellew and Isaku Wada. The Mersenne Twister is an algorithm. HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE. generator is also fast; it avoids multiplication and division, and it benefits from caches and pipelines. For more information see the inventors' web page at http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html

Ngày đăng: 08/07/2014, 21:20

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan