Go to Post you might want to consider the Edu-Robo-Whatevertheheckitscalled RC - Matt Krass [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Spotlight this post!  
Unread 31-07-2012, 17:29
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,093
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Replacing duplicates in a randomly generated array


Simple (and very fast) TP7 implementation:

Code:
{ Choose 20 numbers from the set [1..10000] with no duplicates }

CONST
size=10000;
choose=20;

VAR
a: array[1..size] of word;

Procedure Initialize;
var i: word;
begin
for i:=1 to size do a[i]:=i;
end;

Procedure Shuffle;
var i,j,temp: word;
begin
for i:=1 to choose do
  begin
  j:=random(size)+1;
  temp:=a[i]; a[i]:=a[j]; a[j]:=temp;
  end;
end;

Procedure Select;
var i: word;
begin
for i:=1 to choose do writeln(a[i]:8);
end;

CONST
cr=#13#10;

BEGIN

write('Initializing...');     Initialize;
write(cr,'Seed the RNG...');  Randomize;
write(cr,'Shuffle...');       Shuffle;
write(cr,'Select...',cr);     Select;
write('done. press ENTER ');  readln;

END.

Last edited by Ether : 31-07-2012 at 17:38.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 14:08.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi