两个数字之间的随机数生成器-MatLab [英] Random number generator between two numbers - MatLab

查看:570
本文介绍了两个数字之间的随机数生成器-MatLab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在MatLab中的两个数字之间创建一个随机数生成器,但是我无法找出正确的方程式.

I am trying to create a random number generator between two numbers in MatLab but I am unable to figure out the correct equation.

我知道您可以使用rand()函数创建随机数,但是如果我希望仅在-.5和.5之间生成数字,该怎么办?这可以在MatLab中完成吗?

I know that you can use the rand() function to create random numbers but what if I wanted to have numbers only generated between -.5 and .5? Is this possible to accomplish in MatLab?

推荐答案

调整间隔的答案列在rand()的帮助部分:

The answer for adjusting the interval is listed in the help section on rand() :

示例1

根据间隔[a,b]上的均匀分布生成值: r = a + (b-a).*rand(100,1);

Generate values from the uniform distribution on the interval [a, b]: r = a + (b-a).*rand(100,1);

这篇关于两个数字之间的随机数生成器-MatLab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆