免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4169 | 回复: 3
打印 上一主题 下一主题

存储过程中如何产生随机数? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-06-01 13:15 |只看该作者 |倒序浏览
请教:
      存储过程中如何产生随机数?

论坛徽章:
0
2 [报告]
发表于 2007-06-01 19:00 |只看该作者
from iiug faq


  1. 4.8.8 How do I generate random numbers in SPL?
  2. On 8th Dec 1997 [email]johnl@informix.com[/email] (Jonathan Leffler) wrote:-

  3. Since that's the case, we need a proper random number generator. On the assumption that the C Standard committee knew roughly what they were doing when they specified a random number generator in the ISO 9899:1990 standard, here's an implementation of that generator in two functions, sp_setseed(0 and sp_random(). The range of returned values is 0..32767. Note the comment about MOD. That was in a 9.12.UC2 IUS system.

  4. -- @(#)$Id: ifaq04c.htm,v 1.11 1999/01/09 14:30:06 root Exp $ -- -- Simple emulation of SRAND and RAND in SPL -- Using random number generator suggested by C standard (ISO 9899:1990)


  5. CREATE PROCEDURE sp_setseed(n INTEGER)
  6.         DEFINE GLOBAL seed DECIMAL(10) DEFAULT 1;
  7.         LET seed = n;
  8. END PROCEDURE;

  9. CREATE PROCEDURE sp_random() RETURNING INTEGER;
  10.         DEFINE GLOBAL seed DECIMAL(10) DEFAULT 1;
  11.         DEFINE d DECIMAL(20,0);
  12.         LET d = (seed * 1103515245) + 12345;
  13.         -- MOD function does not handle 20-digit values...  Dammit!!
  14.         LET seed = d - 4294967296 * TRUNC(d / 4294967296);
  15.         RETURN MOD(TRUNC(seed / 65536), 32768);
  16. END PROCEDURE;
复制代码

论坛徽章:
0
3 [报告]
发表于 2007-06-01 19:06 |只看该作者

论坛徽章:
0
4 [报告]
发表于 2007-06-01 19:18 |只看该作者
呵呵 wenlq大哥  谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP