Clear Filters
Clear Filters

about rand and randi command

3 views (last 30 days)
hi, i was wondering about how can i include number '0' in a randi command.
when i use it like 'randi(10)' it is always giving me numbers 1 to 10 but i need '0' also.
HELP please :D

Accepted Answer

Sriram Tadavarty
Sriram Tadavarty on 15 Mar 2020
Hi Oguzhan,
For the sample code, you can use this function signature
a = randi([0 10],1,1); % it will generate a random integer number from 0 (lower limit) to 10 (upper limit) of size 1 x 1
Here is the documentation link of randi, which provides more examples.
Hope this solves your issue.
  1 Comment
Oguzhan Sanliturk
Oguzhan Sanliturk on 15 Mar 2020
Totally understood! Thanks for your time Sriram!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!