JRS: In article <52FB9BFB446278D4.541CA6470E12074B.33E544F47831D...@lp.a

irnews.net>, seen in news:comp.lang.pascal.misc, Clif Penn

<clifp...@airmail.net> wrote at Tue, 10 Jul 2001 17:49:36 :-

##### Quote

>On Tue, 10 Jul 2001 22:15:39 GMT, yskun...@chello.no (?ystein

>Skundberg) wrote:

>> ...

>>So the point is that the string should only contain different

>>characters, not any two of the same kind.

Any method involving choosing at random and scanning to see if already

used will become more and more inefficient as the number of remaining

possibilities diminishes.

ISTM that the best way is to generate a string of the maximum possible

length, N, with all characters allowable and different, then to use this

as a source.

Generating the string of length N is basically equivalent to dealing

numbers 0..(N-1); see

<URL: http://www.merlyn.demon.co.uk/pas-rand.htm#Deal>

which has, for cards

for J := 1 to 52 do begin

K := Random(J)+1 ; A[J] := A[K] ; A[K] := J end ;

If your N allowable characters are X to Y, then perhaps

A[0] := N ;

for J := 1 to N do begin

K := Random(J)+1 ; A[J] := A[K] ; A[K] := char(Pred(J)+Ord(X)) end ;

which will need adjustment of strings are not stored as in Turbo Pascal.

See also Rifkind, /loc. cit./

If the questioner is really using TP or BP, then

news:comp.lang.pascal.borland should be used.

--

? John Stockton, Surrey, UK. j...@merlyn.demon.co.uk Turnpike v4.00 MIME. ?

<URL: http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;

<URL: http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b. mFAQ;

<URL: ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.