Generate random numbers without repeating a value: Difference between revisions

Content added Content deleted
m (→‎{{header|Wren}}: Added libheader.)
m (→‎{{header|REXX}}: elided the commatizing code.)
Line 73: Line 73:
if datatype(seed, 'W') then call random ,,seed /*Specified? Then use the seed. */
if datatype(seed, 'W') then call random ,,seed /*Specified? Then use the seed. */
w= 6
w= 6
title= ' random integers (1 ──► ' commas(n)") with no repeats"
title= ' random integers (1 ──► ' n") with no repeats"
say ' index │'center(title, 1 + cols*(w+1) ) /*display the output title. */
say ' index │'center(title, 1 + cols*(w+1) ) /*display the output title. */
say '───────┼'center("" , 1 + cols*(w+1), '─') /* " " " separator*/
say '───────┼'center("" , 1 + cols*(w+1), '─') /* " " " separator*/
Line 86: Line 86:
$=; idx= 1
$=; idx= 1
do o=1 for n; x= @.o /*obtain a random integer from random @*/
do o=1 for n; x= @.o /*obtain a random integer from random @*/
$= $ right( commas(x), w) /*add an integer to the output list. */
$= $ right( x, w) /*add an integer to the output list. */
if o//cols\==0 then iterate /*have we populated a line of output? */
if o//cols\==0 then iterate /*have we populated a line of output? */
say center(idx, 7)'│' substr($, 2); $= /*display what we have so far (cols). */
say center(idx, 7)'│' substr($, 2); $= /*display what we have so far (cols). */
Line 94: Line 94:
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible show residual output.*/
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible show residual output.*/
say '───────┴'center("" , 1 + cols*(w+1), '─'); say
say '───────┴'center("" , 1 + cols*(w+1), '─'); say
exit 0 /*stick a fork in it, we're all done. */
exit 0 /*stick a fork in it, we're all done. */</lang>
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
<pre>