Re: string generation




In article <lnvf5bvmag.fsf@xxxxxxxxxxxxxxx>, Keith Thompson <kst-u@xxxxxxx> writes:
> "Emmanuel Delahaye" <emdel@xxxxxxxxxxxxxx> writes:
> > Ken Human wrote on 22/05/05 :
> >> I want to generate every possible 16 character combination of the
> >> characters 0-9, A-Z, and a-z programatically. My current code
> >> follows:
> >
> > Really ? It may take hours or days to print them out... Sounds like a
> > cracking device...
>
> Hours or days? You'd better buy a sweater; it's going to get chilly
> after the sun burns out (which will happen long before this thing is
> finished).

Yes, but it still sounds like a cracking device, Dangermouse!

Of course, there's no need to generate them anyway. We already have
the list, in a handy compressed form that allows random access. Just
pick an integer between 0 and 62**16-1 and convert it into its base-
62 representation. A function implementing that algorithm serves as
the "array" of values, and its parameter as the "index".

Iteration is slower than iterating through an actual array, but since
constructing the actual array is, er, infeasible, that hardly matters.

(64 characters would actually be better here, since converting a
number in "pure binary" representation to base 64 is easier than
converting to base 62, but neither is difficult.)

--
Michael Wojcik michael.wojcik@xxxxxxxxxxxxxx

Push up the bottom with your finger, it will puffy and makes stand up.
-- instructions for "swan" from an origami kit
.



Relevant Pages

  • Resolving a macro (was: string generation)
    ... > Yes, but it still sounds like a cracking device, Dangermouse! ... > algorithm serves as the "array" of values, ... > converting to base 62, ... computed from the actual hexchars definition. ...
    (comp.lang.c)
  • Re: help needed on coversin of an char array to an integer
    ... Im kinda stuck in a project at a point where i need an array to ... Converting a character to it's numeric value is a ... '0' - '9' are contiguous in the character ... If you can guarantee that your character set has contiguous alphabetics ...
    (comp.lang.c)
  • RE: Converting a string to an array?
    ... Converting a string to an array? ... string into a character array. ...
    (comp.lang.python)
  • Re: Need help with textboxes
    ... character into the input box. ... one of assigning the reference to a variable: ... All forms and their children are stored in an array ... No. Bracket property accessors allow their argument to be any string value. ...
    (comp.lang.javascript)
  • Help in Spanish translation of the description of UDFs
    ... functions of minimum / maximum values among elements of an array column. ... GETALLWORDS- Inserts the words from a string into a global dimensioned ... WORDTRAN- Searches a character string for occurrences of a first word, ... ARRAYSUM- Returns the sum of all or a specified range of numeric (and/or ...
    (microsoft.public.fox.helpwanted)