gpt4 book ai didi

r - 如何在R中生成0和1之间没有0和1的随机数?

转载 作者:行者123 更新时间:2023-12-04 10:27:15 28 4
gpt4 key购买 nike

我想在 R 中使用 runif(n=1,min=0,max=1) 生成随机数,但我不想要点 0 和 1,我该如何修改它以实现我的目标?

我认为它确实以某种方式生成了 1,请在此处查看我的代码

randomDim = round(runif(1)*3)+1;randomDim

# [1] 4

最佳答案

runif 的文档状态:

‘runif’ will not generate either of the extreme values unless ‘max = min’ or ‘max-min’ is small compared to ‘min’, and in particular not for the default arguments.



因此,已经保证不产生0或1,所以不需要修改。

关于r - 如何在R中生成0和1之间没有0和1的随机数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29219878/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com