Sql Random Number Between 1000 and 9999

Sql Random Number Between 1000 and 9999
Written by Thomas Brown

There is no direct function in sql that chooses a random number between two numbers. But there is a function named rand(). This function gets no parameters, it returns decimal number between 0 and 1. With this function we can get random number between 1000 and 9999. You can see the code below…

Example -1

The Explain of The Code above.

First rand metod executes, For example it returned 0,254587…. value. We multiply this number by 9000. 0,254587*8999 = 2291,283. Then floor method executes. This function rounds the value floor. Then we get the 2291 value.

Also you can see the related posts below….

Sql random number between 1 and 100

Sql Random Number Between 0 and 1 

Mysql Random Number Between 1 and 100

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: