MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   【求助】如何产生0到8之间的整数随机数? (https://www.labfans.com/bbs/showthread.php?t=776)

tan8112 2007-08-25 15:50

【求助】如何产生0到8之间的整数随机数?
 
如何产生0到8之间的整数随机数?
谢谢

dnping 2007-08-25 19:01

randperm(8)
从里面随便取一个就可以了。

ymy2008 2007-08-25 20:13

[QUOTE=dnping;3190]randperm(8)
从里面随便取一个就可以了。[/QUOTE]

这个ms只能把1~8随机排好哦

spy1120 2007-08-26 15:03

round(8*rand)

slgu 2007-08-28 17:11

random('unid',9)-1

A120 2007-08-29 09:19

x = randint(8);

Blue_Breeze 2007-08-29 20:29

>> randint(8)

ans =

1 0 1 0 0 0 0 1
1 1 0 0 0 0 1 0
0 1 0 1 1 1 1 0
1 0 0 1 1 1 0 0
0 0 0 0 1 1 0 0
0 1 0 0 0 0 1 1
1 1 0 0 0 1 0 0
1 0 1 1 0 0 1 1

Blue_Breeze 2007-08-29 20:36

randint不是很恰当
要实现的话,建议语句
randint(1,1,9)

Blue_Breeze 2007-08-29 21:00

randperm(8)只是将1到8的整数随机排列


所有时间均为北京时间。现在的时间是 12:15

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.