Using randi instead of floor and rand.

2 ビュー (過去 30 日間)
Giuseppe
Giuseppe 2014 年 5 月 1 日
回答済み: Star Strider 2014 年 5 月 1 日
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.

採用された回答

Star Strider
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 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by