On Aug 19, 10:52*pm, RICK <R...@xxxxxx> wrote:
Quote:
> But, my characters are alphanumeric.
>
> What I have done is to create seven random letters followed by one random
> number and one random special character.
>
> I now want to randomize these nine characters into another
>
Rick,
I hope the code is fairly self-explanatory. Basically, it finds random
numbers between 1 and 9, removing them from pattern (the acceptable
choices) until pattern is empty, and appends those found to selection.
Then it iterates through selection, using the numbers therein as
offsets into original.
Kind regards,
Bruce.
dim a
dim n
dim original
dim pattern
dim selection
dim final
dim i
randomize timer
original = "abcdefg1@"
pattern = "123456789"
selection = ""
final = ""
' pick 9 random numbers without duplicates
do
n = int( rnd * 9 ) + 1
i = instr(pattern, cstr(n))
if i > 0 then
pattern = left(pattern,i-1) & mid(pattern,i+1)
selection = selection & cstr(n)
end if
if len(pattern) = 0 then exit do
loop
'use those numbers to select items from the original
for i = 1 to len(selection)
n = mid(selection,i,1)
final = final & mid(original,n,1)
next
wscript.echo original, selection, final
---
Sample run:
abcdefg1@ 329675841 cb@xxxxxx