[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Repeating bug (error: subscript indices must be either positive inte
Re: Repeating bug (error: subscript indices must be either positive integers or logicals)
Thu, 28 Apr 2011 17:18:53 -0400
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:18.104.22.168) Gecko/20110307 Fedora/3.1.9-0.39.b3pre.fc14 Lightning/1.0b2 Thunderbird/3.1.9
On 04/27/2011 01:59 AM, Mike Ragan wrote:
I get the following message when I run Passgen:
subscript indices must be either positive integers or logicals.
error: called from `OnePassword' in file
C:\Users\Mike\DOCUME~1\2010-11\EG1002\OnePassword.m near line 12,
Octave is complaining about those code lines:
randomchar = round(rand(1)*62)
allchar = [uppercase lowercase digits];
Password(n) = allchar(randomchar);
So your problem occurs when rand(1) is pretty close to zero,
specifically when it's smaller than 1/62; your randomchar ends up being
zero which is an illegal index into the allchar array.
You need to make sure that the randomchar index falls within the range
1..length(allchar), for instance:
randomchar = 1+round(rand(1)*length(allchar))
Fortunately, rand() never returns 1 so we won't get caught on the other
end of this interval.