bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

$RANDOM bug


From: Antoni Sawicki
Subject: $RANDOM bug
Date: Sun, 20 May 2001 00:14:54 +0100

Hi,

I'm not sure it's really a bug, but for me it is.

VER   : 2.every
HW/OS : every
CC=   : gcc (every)

echo $(($RANDOM%2))

returns sequencial 0 and 1 and 0 and 1 and 0 and 1, I mean:

01010101010101010101 ... and not "random", what should be:
00101101110010001111 ... etc...

It causes positioning problems in my scrip:

#!/bin/bash
#
# Random Password Generator v2 for BASH 2.x by Antek Sawicki <address@hidden>
#

NMATRIX='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
SMATRIX='address@hidden&*()_+-={}[],.<>?`~;:"'

NLENGTH='6'
SLENGTH='2'

while [ ${n:=1} -le $NLENGTH ]
do
        [ "${m:=$SLENGTH}" -le "0" ] && unset m
        PASS="$PASS${NMATRIX:$(($RANDOM%${#NMATRIX})):1}${SMATRIX:$(($RANDOM%${#SMATRIX})):${m:+1}}"
        let n+=1 m-=1
done

echo "$PASS"

The characters from SMATRIX are placed only in even positions.

Regards,
Antoni



**********************************************************************
Privileged/Confidential Information may be contained in this
message. If you are not the addressee indicated in this message
(or responsible for delivery of the message to such person), you
may not copy or deliver this message to anyone. In such case,
you should destroy this message and kindly notify the sender by
reply email. Please advise immediately if you or your employer do
not consent to Internet email for messages of this kind. Opinions,
conclusions and other information in this message that do not relate
to the official business of Marrakech and shall be understood as
neither given nor endorsed by it.
**********************************************************************

reply via email to

[Prev in Thread] Current Thread [Next in Thread]