LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-05-2011, 07:36 AM   #1
jumpingj
LQ Newbie
 
Registered: Apr 2011
Posts: 6

Rep: Reputation: 0
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
 
Old 04-05-2011, 10:28 AM   #2
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
Quote:
Originally Posted by jumpingj View Post
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 View Post
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.)
 
Old 04-06-2011, 04:55 AM   #3
jumpingj
LQ Newbie
 
Registered: Apr 2011
Posts: 6

Original Poster
Rep: Reputation: 0
Helllo

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


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Generate SPECIAL alphanumeric WORDLIST - no repeating characters side-by-side Stanley_212 Programming 33 10-13-2022 06:06 PM
Auto increment an alphanumeric ID in C PMR Programming 3 05-22-2009 11:08 AM
cp will copy in any order, not alphanumeric DaveQB Linux - Software 3 01-10-2009 09:15 PM
AUTO_INCREMENT + alphanumeric in MySQL? ta0kira Programming 12 10-03-2008 12:46 PM
arithmetic on alphanumeric in PERL gaynut Programming 2 09-08-2008 09:09 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration