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>You are looking for a (pseudo-) random number generator, and there are many to choose from. Scale what your chosen one gives you (usually between 0 and 1) and fill your sequences by calling it repeatedly. Or use the scaled sequence to pull from ASCII tables if you want characters.</p>

<p>Perl comes with a builtin <a href="http://perldoc.perl.org/functions/rand.html" rel="nofollow"><code>rand</code></a>, which since Perl 5.20 is actually Perl's. Prior to that it used whatever was available on the system. This is a toy generator, not suitable for serious work. For reasons see for example <a href="https://www.nu42.com/2014/05/perl-5200-brings-better-prng-to-windows.html" rel="nofollow"><code>Sinan Unur's analysis</code></a> or older <a href="http://wellington.pm.org/archive/200704/randomness/#slide0" rel="nofollow"><code>Wellington's</code></a> thorough discussion. If you don't care for the period, correlations in higher dimensions, and such, it is probably OK.</p>

<p>There are modules in Perl which supply good alternatives. For example, <a href="http://search.cpan.org/~mkanat/Math-Random-Secure-0.06/lib/Math/Random/Secure.pm" rel="nofollow"><code>Math::Random::Secure</code></a> claims cryptographically secure quality and is probably more than adequate.  If you need truly random numbers pooled from measurements of natural phenomena, and not pseudo-random sequences generated by a computer, the <a href="https://www.random.org/" rel="nofollow"><code>random.org</code></a> has them. The Perl module <a href="https://metacpan.org/pod/Net::Random" rel="nofollow"><code>Net::Random</code></a> provides interface to it, or to other sources of your choosing.</p>

<p>As for the code, once you try something let us know if there are problems.</p>

<hr>

<p>A toy example</p>

<pre><code>use warnings 'all';
use strict;
use feature 'say';

my $max = 999_999;

my @rand_ints;

for (1..$max) {
    push @rand_ints, sprintf("%0*.0f", length($max), rand() * $max);
}

say for @rand_ints;
</code></pre>

<p>This prints reasonably random integers between <code>000000</code> and <code>999999</code>, one per line.</p>

<hr>

<p>It is possible that the requirement against "<em>repeating sequences</em>" means that no digits may repeat in a number (and that <code>010101</code> should be thrown out), thanks to <a href="http://stackoverflow.com/users/5771269/cdlane">cdlane</a> for a comment.</p>

<p>In that case I still recommend to pull from a good generator, but test each number. If it sports the offending repetitions discard and pull the next one. This will extend the needed sequence greatly, along with the processing time.  For example</p>

<pre><code>while (1) {
    my $rint = sprintf("%0*.0f", length($max), rand() * $max);
    next if rep_digits_seqs($rint);
    push @rand_ints, $rint;
    last if @rand_ints == $max;
}

sub rep_digits_seqs {
    return ($_[0] =~ /(\d)\1/ or $_[0] =~ /(\d\d)\1/);
}
</code></pre>

<p>The call to <a href="http://perldoc.perl.org/functions/sprintf.html" rel="nofollow"><code>sprintf</code></a> may seem wrong before the test for numbers that may fail anyway, but without it we would occasionally test un-rounded ones, resulting in errors. This excludes any repeated digits (<code>11</code>, <code>88</code>), and any repeated two-digit sequences like <code>1212</code> or <code>7575</code>. But it also excludes <code>0012...</code>. Adjust as needed.</p>

<p>Note that this particular requirement, of avoiding repetitions, results in repeated numbers. Consider the case where we have 10 digits to form a six-long number, without repetitions. This can be done in "<em>10 choose 6</em>" ways, which is <code>10!/(6!4!)</code> (factorials), ie. 210. So that's how many different numbers we'd have.  Here we have more, since only some repetitions are excluded -- but it still seems to be a far cry from the needed million. So if we produce a million numbers some (many) will have to appear more than once.  What also means that most numbers are likely to fail and we'd need a <em>very</em> long original sequence. I doubt that what comes out is a good pseudo-random sequence.</p>

python bash perl random sequence