Is there a way in Matlab using the pseudo number generator to generate numbers within a specific range?

前端 未结 2 1793
难免孤独
难免孤独 2020-12-04 02:43

For example:

round(7*rand(1,5))

Generates 5 numbers between 1 and 7 Is there a way to generate 5 random numbers between 5 and 7? Or an abst

2条回答
  •  情话喂你
    2020-12-04 03:11

    More generally:

    minInt = 5;
    maxInt = 7;
    numInts = 10;
    
    r = randi([minInt, maxInt],[1,numInts])
    
    r =
    
     6     7     7     7     6     5     5     5     7     5
    

提交回复
热议问题