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)

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

 No comment posted at this time


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

News archive



[Sitemap]