Total Pageviews

Thursday, April 24, 2014

math.ramdom

Math.random()
ប្រើសំរាប់ត្រឡប់មកវិញនៅ pseudo-random number ចេញពី sequence with uniform distribution។ ហ្វាំងសិននេះមាន interface ដូចនឹង simple pseudo-random ដែរ ដែលវានឹង generator function rand ដែលផ្តល់ដោយ ANSI C។ no guranntees can be given for its statistical properties។ វាមាន៣វើរសិនសំរាប់ហ្វាំងសិននេះ
១. នៅពេលហៅវាដោយមិនមាន argument, វានឹងត្រឡប់នៅ pseudo random real number នៅក្នុង range [0,1]
២. នៅពេលហៅវាដែលមាន integer numer m, math.random ដែលនឹងត្រលប់តំលៃ pseud0 random integer នៅក្នុង range [1,m]
៣. នៅពេលហៅវាជាមួយនឹង two integer number m & n, math.random ត្រឡប់ជា uniform pseudo-random integer នៅក្នង range [m,n]
Syntax: math.random()
Math.randoom(m)
Math.random(m,n)
M(ជំរើស)វាជាចំនួនលេខ
N(ជំរើស)វាជាចំនួនលេខ
សូមមើលកូដះ
print(math.random())        ---> a number between 0 and 1
print(math.random())        ---> another number between 0 and 1
print(math.random(10))      ---> an integer between 1 and 10 (inclusive)
print(math.random(7080))  ---> an integer between 70 and 80 (inclusive)


No comments:

Post a Comment