Numeric output and dont echo repeating numbers for ex 1010101; 2020202, 1212121
<p>Looking for a script that can pipe or print to file and generate a random, non repeating output wordlist/numberlist [crunch for example can do that with the -d option but 10101 etc dont get sorted out]. </p>

<p>Example:  a numeric list <code>000000-999999</code> and written to a file / pipe to program all numbers but no repeating sequences like <code>1010101; 2020202; 12121212, 13131313 ......</code> or repeating numbers <code>11 222 3333 44444 .....</code></p>

<p>EDIT:</p>

<p>Great answers so far, thank you.</p>

<p>Heres a little hack that does pretty much what is intented, but not perfectly.
Looking for a solution to have the result directly, going through the answers asap.</p>

<pre><code>sed -i  -e '/1010/d' -e '/1212/d' file.txt
</code></pre>

<p>Source:
<a href="http://stackoverflow.com/questions/5410757/delete-lines-in-a-text-file-that-containing-a-specific-string">Delete lines in a text file that containing a specific string</a></p>

<p>OK, this is my definition of finding and eliminating repetitive strings. The idea is to:</p>

<ul>
<li>draw a random string of numbers and zeropad it (<code>str</code>)</li>
<li>store the first two characters (<code>replen</code> actually) of every substring to an array (<code>prefix</code>) and if there is a collision, there is a repetition in the string and another candidate is drawn, ie: <code>12312</code> -> <code>12</code>, <code>23</code>, <code>31</code>, <code>12</code> and the latter <code>12</code> is a collision and therefore the string is repetitive.</li>
<li>downside to current implementation is that 3 consecutive same numbers is considered a repetition: <code>666</code> -> <code>66</code>, <code>66</code> collision. This, however, is could be considered repetition but then again <code>66</code> is also and @rossum's solution should be used.</li>
</ul>

<p>awk:</p>

<pre><code>BEGIN {
#    if(seed=="") {                              # note to self...
#        print "-v seed=$RANDOM"
#        exit
#    }
    replen=2                                     # minimum length of possible repetition
    len=8                                        # set desired str length
    srand(seed)                                  # set the seed for rand
    prefix[""]
    while(length(prefix)&lt;len-1) {                
        str=sprintf("%0"len"d",rand()*10^len-1)  # get a random string of numbers, zeropad
        for(i=1;i&lt;=len-(replen-1);i++) {         # create prefix array
            key=substr(str,i,replen)             # length(key) to array is 2
            if(key in prefix) {                  # if duplicate found start over
                delete prefix
                break
            }
            else                                 # if key candidate not a duplicate
                prefix[key]                      # add it to array
        }
    }
    print str                                    # print str after while
}
</code></pre>

<p>Run it:</p>

<pre><code>$ awk -v seed=$RANDOM -f random.awk
34592181
</code></pre>

<p>No sanity checking is used for <code>len</code> or <code>replen</code>.</p>

python bash perl random sequence