Random range processing method for SQL Server random numbers

Source: Internet
Author: User
Tags rand

Recently in the database on the random number, really touch I want to die heart all have, before all through the rand () function of PHP to deal with a range of random numbers, but recently in the processing of large amounts of data processing millions by PHP too slow, forced, only to find the SQL own processing method.


Body Correlation function ROUND () RAND ()

Let's start by analyzing the meaning of round () and Rand ().

Round () is the method used to take the number of digits after the decimal point, and the returned value is rounded.

Round (A, b) where a represents the number of processed numbers, such as 20.9, 55.08, 33, etc., the number of digits reserved

Round (21.2,0) represents the integer portion of 21.2 + 0 digits after the decimal point, that is, the result is 21, rounded.

Rand () is a repeatable random number that takes directly within a 0~1


topic comes, gets the random number in the specified range

Round (rand () *n+1,0) haha

To parse is to take a repeatable integer within a 1~n+1.

Done

Random range processing method for SQL Server random numbers

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.