Random Bitting Generator (with constraints)
As per the comment in the header, you can run this on a Windows/Win32 system via the Windows Script Host (which I believe is installed on Windows XP and later systems as standard). Cut the code out and paste it into a text file called combinate.js
Open a window with the command prompt (usually C:\>) and cd to the directory in which you saved combinate.js
At the command-line enter the following:
cscript combinate.js
The prgram should spit out 12 5-digit codes with certain arbitrary constraints (that may or may not suit your need). The major parameters have been implemented as pseudo-constants (JavaScript doesn't support real symbolic constants AFAIK) to make the program easier to alter. If you don't feel confident adapting this code then just post your requirement and myself or another member will help.
- Code:
// combinate.js
// At Windows command-line enter:
// C:\> cscript combinate.js
//
var NUM_DIGITS = 5
var INTERVAL_START = 1
var INTERVAL_END = 6
var BATCH_SIZE = 12
var REGEX_1 = /^6/
var REGEX_2 = /61/
var REGEX_3 = /16/
function randomWithinInterval(from, to)
{
return Math.floor(Math.random() * (to - from + 1) + from)
}
var previousCut = ""
var currentCut = ""
var code = ""
var batchCount = 0
while( batchCount < BATCH_SIZE )
{
for(i = 1; i <= NUM_DIGITS; i++)
{
currentCut = randomWithinInterval(INTERVAL_START, INTERVAL_END)
// Filter out identical contiguous digits and increment/decrement pattern
while ( previousCut == currentCut ||
(previousCut + 1) == currentCut ||
(previousCut - 1) == currentCut )
{
currentCut = randomWithinInterval(INTERVAL_START, INTERVAL_END)
}
previousCut = currentCut
code += currentCut
}
// Filter out unwanted codes (MACS violations)
if ( code.search(REGEX_1) < 0 &&
code.search(REGEX_2) < 0 &&
code.search(REGEX_3) < 0 )
{
batchCount++
WScript.Echo(code)
}
code = ""
}