Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mysql Rand() between 2 values
ROUND((RAND() * (max-min))+min)
@liuxiaochuang

This comment has been minimized.

Copy link

commented Mar 3, 2018

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

@Wiimm

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.