-
-
Notifications
You must be signed in to change notification settings - Fork 161
Modify get_random() #677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modify get_random() #677
Conversation
@val213: no appropriate reviewer found, use |
user/dadk/config/dog_0_1_0.dadk
Outdated
@@ -5,7 +5,7 @@ | |||
"rust_target": null, | |||
"task_type": { | |||
"BuildFromSource": { | |||
"Git": { | |||
"Git": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里为什么要删除缩进?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
之前把编译源修改回本地测试了,最后改回去的时候没注意缩进的问题。已在最新的push中修复
@dragonosbot author |
kernel/src/syscall/misc.rs
Outdated
@@ -75,8 +76,11 @@ impl Syscall { | |||
let mut ret = Vec::new(); | |||
let mut count = 0; | |||
while count < len { | |||
//对len-count的长度进行判断,remain_len小于4则循环次数和remain_len相等 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要fmt,并且//
后面要有空格
在原来的实现中,代码尝试将32位随机数(rand())分解为4个字节,并且每个循环中生成4个字节,然后推入ret向量。如果len是1,那么这个循环会产生4个额外不需要的字节,这可能是导致之前提到的错误的原因。 #675
第二种实现则简单地每次生成一个随机字节(rand() as u8),并直接推入ret向量,只有当count小于len时才继续循环。这样,无论len是多少,它都会生成正好len个字节的随机数。