在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 3181|回复: 11

弱问一个简单的问题

[复制链接]
发表于 2009-2-23 16:07:55 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
最近正在学习verilog,想问一下为什么{random}%60产生的是0~59之间的数
也就是random加拼接运算符后产生的值就略去了负的部分呢?
期望有人解答,谢谢!~!~!~!
发表于 2009-2-23 17:40:20 | 显示全部楼层
You ask a very good question.

According IEEE 1364-2005 page 341:

The system function $random provides a mechanism for generating random numbers. The function returns
a new 32-bit random number each time it is called. The random number is a signed integer; it can be positive
or negative. For further information on probabilistic random number generators, see 17.9.2.
The seed argument controls the numbers that $random returns so that different seeds generate different
random streams. The seed argument shall be either a reg, an integer, or a time variable. The seed value
should be assigned to this variable prior to calling $random.
For example:
Example 1—Where b is greater than 0, the expression ($random % b) gives a number in the following
range: [(-b+1): (b-1)].

So I think your assumption is wrong.
 楼主| 发表于 2009-2-23 18:27:27 | 显示全部楼层
我是看到夏宇闻老师书上他是这么写的,因为我不是很明白,所以才问的。
未命名.bmp
发表于 2009-2-23 19:11:20 | 显示全部楼层
很简单,说明书错了:)
发表于 2009-2-23 21:33:30 | 显示全部楼层
好好干,你能成为一个优秀的工程师的.

[ 本帖最后由 humann 于 2009-2-24 03:09 编辑 ]
发表于 2009-2-23 21:51:13 | 显示全部楼层
夏宇闻 is right. I make a mistake.

The {} treats all parameter as unsigned  value and so products an  unsigned value too.

You can run the following test program in simulator.

You can try to remove {} to watch the different effect.


// test program
module top;      
   initial       repeat(80) #1 $display("%d ($random) mod 60  ->  %d", $random, {$random}%60);   
   initial       #100 $finish;           
endmodule
头像被屏蔽
发表于 2009-2-24 09:33:47 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2009-2-24 10:46:26 | 显示全部楼层
我的理解也是,{random}%相当于对正数的求%,
发表于 2009-2-24 15:50:00 | 显示全部楼层

回复

对这个系统函数,我还没有用过。不过现在学到了一些新的知识了。
发表于 2009-2-24 19:38:26 | 显示全部楼层
恩,不错的问题
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

×

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-7 10:36 , Processed in 0.045671 second(s), 12 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表