Generating random integer from -x to x
1 次查看(过去 30 天)
显示 更早的评论
I need to find a way to generate a random integer from -x to x for example -5 to 5
0 个评论
采纳的回答
更多回答(1 个)
per isakson
2014-3-12
编辑:per isakson
2014-3-12
2*x*rand-x produces uniformly distributed numbers
Doc says: Example 1, Generate values from the uniform distribution on the interval [a, b]:
r = a + (b-a).*rand(100,1);
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!