op_dist_uniform()

摘要

生成一个在有限范围内均匀分布的随机值,该范围从 0.0 开始,延伸至(但不包含)指定的上限。

语法

op_dist_uniform (limit)
参数 类型 说明
limit double 均匀分布值范围的边界

返回类型

double

生成的均匀随机值。

该值介于 0.0(包含)与指定上限(不包含)之间。

示例

摘自:示例模型(models/std/eth_net);进程模型(eth_mac);状态(BACKOFF);enter execs。

/* compute backoff interval using truncated binary exponential process; */
/* the unit for retransmission scheduling is the slot time and the upper */
/* bound is based on the # of transmissions to date of the current frame */

/* if this is the first attempt, there are two possible backoff slots. */
if (attempts == 1) max_backoff = 2;

/* otherwise the number of possible slots grows exponentially until */
/* it exceeds a fixed limit. */
else if (attempts <= BACKOFF_LIMIT)
	max_backoff = max_backoff * 2;

/* obtain a uniformly distributed random integer between 0 and backoff limit */
backoff_slots = op_dist_uniform (max_backoff);

/* set a timer for the end of the backoff interval */
op_intrpt_schedule_self (op_sim_time () + backoff_slots * SLOT_TIME, 0);

详情

本内核过程使用的随机数流由对 BSD random() 过程的调用生成,并由 Dist 包的所有内核过程以及生成器模块共享。随机数流依赖于一个初始种子,可通过仿真环境属性“seed”加以改变(详见第 1 章 “Executing a Discrete Event Simulation” 第 1 页)。若仿真输入完全相同(包括相同的随机种子),仿真结果即可复现。

如果为 limit 参数指定负值,则返回的值将是一个均匀分布的负数,其值 <= 0 且大于 limit。

用途

提供一种获取均匀分布随机数的机制,用于一般建模目的。一个典型用途是计算数据链路协议所使用的随机超时时间。

错误

  • 不捕获任何错误。

参考

本站文档由 北京智网畅联科技有限公司 整理、翻译并提供 · Documentation compiled and provided by Beijing ZNetLink Technology Co., Ltd.

交流群 · QQ Group:OPNET/智网妙算网络仿真交流群(群号 486383494)

原文档 © 2017 Riverbed Technology · 本站为公益翻译,由 AI 辅助完成,请仔细甄别

Original documentation © 2017 Riverbed Technology. Community translation, AI-assisted. Contact: jiazequn@znetlink.com