_asp Foundation of Rnd function in ASP

Source: Internet
Author: User

Rnd function

Describe
Returns a random number.
Grammar
rnd[(number)]
The number argument can be any valid numeric expression.

Description
The RND function returns a value less than 1 but greater than or equal to 0. The value of number determines how the Rnd generates random numbers:
If number is Rnd generated
is less than 0 each time the same value, using number as the seed.
is greater than the next random number in the 0 sequence.
equals zero The most recently generated number.
Omits the next random number in the sequence.

Because each successive call to the RND function uses the previous number in the sequence as the seed of the next number, the same sequence is generated for any initially given seed.

Before calling Rnd, the random number generator is initialized with a Randomize statement without parameters, which has seeds based on the system timer.

To produce a random integer of the specified range, use the following formula:

Int ((upperbound-lowerbound + 1) * Rnd + lowerbound)

Here, the upperbound is the upper bound of this range, and the lowerbound is the lower bound within this range.

--------------------------------------------------------------------------------

Note to repeat the sequence of random numbers, call Rnd with a negative argument immediately before you call Randomize with a numeric argument. Randomize that use the same number value cannot repeat the previous sequence of random numbers.

---------------------------------
Example:
We usually use now to do the seed, so we can get the perfect random sequence, if we need a random number within 1-100
Randomize ()
N=int ((100-1+1) *rnd (now ()) +1)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.