Using randi instead of floor and rand.
조회 수: 1 (최근 30일)
이전 댓글 표시
This is my password generator.
% Password Generator
% 1. Input Parameters
uppercase = 'A':'Z';
lowercase = 'a':'z';
numbers = '0':'9';
letters = [uppercase, lowercase];
characters= [letters, numbers];
% 2. Ouputput Password
passwd_length = input('enter the length');
passwd(1) = letters(randi(numel(letters)));
passwd(2:passwd_length) = characters ( 1 + floor(rand(1, passwd_length - 1) .* numel(characters)) )
In the last line I have used the floor command with rand. Is there a way where I can use randi instead.
댓글 수: 0
채택된 답변
Star Strider
2014년 5월 1일
This is how I’d do it:
passwd(2:passwd_length) = characters (randi(length(characters ), 1, (passwd_length-1)))
댓글 수: 0
추가 답변 (0개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!