LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Generate alphanumeric characterlist - no repeating more then 3 times (https://www.linuxquestions.org/questions/programming-9/generate-alphanumeric-characterlist-no-repeating-more-then-3-times-873088/)

jumpingj 04-05-2011 07:36 AM

Generate alphanumeric characterlist - no repeating more then 3 times
 
Hi Guys
i have spotted that script (something similar that i am looking for)

http://www.linuxquestions.org/questi...y-side-862473/

and i just dont know how to use it.I am not a programmer myself and probably no need for learning that just to create one script!only need your help to modify "wje_lq" script and run it.
thing like :
"Just redirect standard output to a file in the normal manner" ???

and all this

I.Comment out the first definition of *character-set*, by adding a semicon at the beginning of the line.
II.Uncomment the second definition, which just uses "ABC", by removing the semicolon from the beginning of the line.
III.Comment out the first definition of *word-length*.
IV.Uncomment the second definition, which uses a word length of four.

i would like to generate :
10-character combinations of the following characters (lowercase) 23456789abcdef with no more then 3 same letters repeates no metter side by side or within one line (sequence) so lets say

abcdef1234 accept
fabcde1234 accept
ffabcd1234 accept
which is probably permutation with repetable string ( where abc is not equeal to cba etc .so ti speak position does metter)

fffabc1234 not acceptable -----(3 same characters)
ffabcf1234 not acceptable -----( 3 same characters event thought not side by side)

so generally we dont want 3 same characters apper in same line ,
Anybody would kindly challenge that (either linux or mac os scripts)
Thanks for any help and sorry for my bad english,hope you can know what i'm looking for.
Thanks

Nominal Animal 04-05-2011 10:28 AM

Quote:

Originally Posted by jumpingj (Post 4314477)
10-character combinations of the following characters (lowercase) 23456789abcdef

Those are then 40-bit numbers in hexadecimal. (I'm assuming you left out 1 by accident.)

Quote:

Originally Posted by jumpingj (Post 4314477)
with no more then 3 same letters repeates no metter side by side or within one line (sequence)

and this means no nibble (4-bit unit) must be repeated more than twice.

There are 16*16*15*15*14*14*13*13*12*12 = 274743705600 of these sequences. Do you really wish to generate them all, or just random ones?

Random ones are easy to generate using the exclusion method. Just generate 40-bit random numbers, and only print and count those that match your criteria. Here's a simple Bash example. Supply the number of sequences you want as a command-line parameter to this script:
Code:

#!/bin/bash
if [ $# -ne 1 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
    echo "Usage: $0 sequences" >&2
    exit 1
fi
N=$[ $1 -0 ] || exit $?

DIGIT=(0 1 2 3 4 5 6 7 8 9 a b c d e f)
DIGITS=${#DIGIT[@]}

# Loop until the desired number of numbers output.
while [ $N -gt 0 ]; do

    # Generate the random number as an array of digits (in decimal)
    VALUE=( $[RANDOM % DIGITS] $[RANDOM % DIGITS]
            $[RANDOM % DIGITS] $[RANDOM % DIGITS]
            $[RANDOM % DIGITS] $[RANDOM % DIGITS]
            $[RANDOM % DIGITS] $[RANDOM % DIGITS]
            $[RANDOM % DIGITS] $[RANDOM % DIGITS] )

    # Count the number of occurrences for each digit.
    COUNT=()
    for V in ${VALUE[@]} ; do
        COUNT[$V]=$[COUNT[$V]+1]
    done

    # Check if any digits occur more than twice.
    OK=1
    for C in ${COUNT[@]} ; do
        [ $C -gt 2 ] && OK=0
    done
    # Reject those.
    [ $OK -ne 1 ] && continue

    # Output this number.
    for V in ${VALUE[@]} ; do
        echo -n ${DIGIT[V]}
    done
    echo

    # Count the output number.
    N=$[N-1]
done

Note that I intended the above to be an illustrative and easy to modify example on how to do it, it is not necessarily the easiest or even best method. (Personally, I'd use awk for small number of sequences. For massive scale, I'd use a C program with a Mersenne Twister random number generator.)

jumpingj 04-06-2011 04:55 AM

Helllo

Thanks for your help and suggestions Nominal Animal.I will try to build from here...


All times are GMT -5. The time now is 04:33 PM.