News: An extended random function
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)
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)
Comments
| No comment posted at this time |
[Sitemap]

















