Skip to content

Instantly share code, notes, and snippets.

@asika32764
Created August 16, 2014 07:41
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save asika32764/534ad8891a2a3bb8fe05 to your computer and use it in GitHub Desktop.
Save asika32764/534ad8891a2a3bb8fe05 to your computer and use it in GitHub Desktop.
Mysql Rand() between 2 values
ROUND((RAND() * (max-min))+min)
@liuxiaochuang
Copy link

this is OK, but I think the efficiency is very low. I think put rand outside MySQL is a better choice.

@Wiimm
Copy link

Wiimm commented Sep 19, 2018

Really, 1 repository for 1 buggy code line?

For range (min..max( (min inclusive, max exclusive) it is:
FLOOR( RAND() * (max-min) + min )

For range (min..max) (min+max inclusive) it is:
FLOOR( RAND() * (max-min+1) + min )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment