News: An extended random function

Kristian Fiskerstrand's blog

Published: 2006-03-24 17:40:13 . Categories: Computer MySQL

This is a function for MySQL 5.0. The theory behind it is generic. The name condrand is short for conditional random

DELIMITER //

CREATE FUNCTION condrand
(
a INT,
b INT
)
RETURNS INTEGER
NO SQL
BEGIN
RETURN ROUND(a + RAND() * (b-a));
END//

mysql> SELECT condrand(1,3)//
+---------------+
| condrand(1,3) |
+---------------+
| 2 |
+---------------+
1 row in set (0.00 sec)

Bookmark this on google Bookmark this on del.icio.us Submit this to digg Bookmark this at yahoo Bookmark this at reddit Bookmark this at furl Search technorati for links to this page Toggle more

Comments

lin123 - lin123
vs generic. The name condrand is short for conditional random
Email: -hidden- - Website: http://www.hijordan.com Added: 2010-05-31 03:47:54
 
火狐 - 火狐
http://www.ingucci.com
Email: -hidden- - Website: http://www.ingucci.com Added: 2010-06-05 04:14:22
 
lin123 - lin123
http://www.hijordan.com
Email: -hidden- - Website: http://www.hijordan.com Added: 2010-06-09 11:17:19
 
lin123 - lin123
http://www.hijordan.com
Email: -hidden- - Website: http://www.hijordan.com Added: 2010-06-12 05:39:12
 
小猫 - 小猫
vs generic. The name condrand is short for conditional random
Email: -hidden- - Website: http://www.ingucci.com Added: 2010-06-25 05:36:20
 
1|


Name:
Nickname:
E-mail:
Website:
Message:
Read codeImage verification
Put code:

News archive



[Sitemap]