[Gambas-user] Re: Re: Am I doing something wrong?
Rob
sourceforge-raindog2 at ...94...
Wed Jun 29 22:08:14 CEST 2005
On Wednesday 29 June 2005 15:39, A Person wrote:
> My recent workaround is to create a timer with a 1050 delay so that
> each random number generation is at least one second later than the
> previous.
If you REALLY want randomness, you could go outside the box a bit:
public function genpw() as string
dim pw as string
dim c as string
do while true
c = backtick("head -c 1 /dev/random")
if asc(c) > 31 and asc(c) < 127 then
pw = pw & c
if len(pw) >= 8 then return pw
endif
loop
end
/dev/random will block until another random number has been generated.
You can find backtick() in the Gambas documentation by searching for
backtick; it does in earlier versions of Gambas what
c = shell("head -c 1 /dev/random")
would do in 1.9.10.
If dropping all the characters below 31 and above 127 proves to be too
slow for your purposes, put this before the if statement: (actually,
you should be able to remove the if... and endif lines entirely if
you do this)
c = chr(asc(c) mod 96) + 32
or to restrict it to alphanumeric only:
c = mid("abcdefghijklmnopqrstuvwxyz0123456789", (asc(c) mod 36) + 1,
1)
Rob
More information about the User
mailing list