Thread View: comp.lang.pascal.borland
16 messages
16 total messages
Started by Saurabh Sinha
Tue, 07 Dec 1999 00:00
Random function - PASCAL
Author: Saurabh Sinha
Date: Tue, 07 Dec 1999 00:00
Date: Tue, 07 Dec 1999 00:00
19 lines
1288 bytes
1288 bytes
Hi
I have a list of names in pascal, say:
Students = {John, Peter, Lukas, Mario, Manuel, Victory}
Could someone assist me with code to randomly select one of these names
(with no extra spaces).
What I tried:
x := random(5) + 1;
RandomName:=copy('John Peter Lukas Mario Manuel Victory', xx + pos('
','John, Peter, Lukas, Mario, Manuel, Victory'), 6);
Thanks in advance for your help. If its okay, I'd appreciate a reply to:
sinha@mweb.co.za
Saurabh
Re: Random function - PASCAL
Author: Alexander Mueller
Date: Mon, 06 Dec 1999 00:00
Date: Mon, 06 Dec 1999 00:00
18 lines
1536 bytes
1536 bytes
var Students:array[0..5] of string=('John','Peter','Lukas','Mario','Manuel','Victory');
begin
Randomize;
repeat
Writeln(Students[Random(High(Students)+1)]);
until 1=2;
end;
Alex
--
** Pepsi Cola and Animal protection ** || Demonstration gegen Pelzhandel am 11.12.1999
** http://www.pepsibloodbath.com/ ** || http://www.vgt.at/grossdemo.htm/
Author of the free Chatsystem PINO! || Website: http://www.alcomp.net
Available at http://pino.cjb.net || Chat : pinochat.dhs.org:8080
Re: Random function - PASCAL
Author: Jud McCranie
Date: Mon, 06 Dec 1999 00:00
Date: Mon, 06 Dec 1999 00:00
9 lines
1139 bytes
1139 bytes
Alexander Mueller <alexm@gmx.at> wrote: > repeat > Writeln(Students[Random(High(Students)+1)]); > until 1=2; Something that is equivalent to the UNTIL condition is "until false". Jud McCranie
Re: Random function - PASCAL
Author: Jud McCranie
Date: Mon, 06 Dec 1999 00:00
Date: Mon, 06 Dec 1999 00:00
10 lines
1210 bytes
1210 bytes
Alexander Mueller <alexm@gmx.at> wrote: >> Something that is equivalent to the UNTIL condition is "until >> false". > >And? And that's it - nothing else. The neatest way to do it. Jud McCranie
Re: Random function - PASCAL
Author: Alexander Mueller
Date: Tue, 07 Dec 1999 00:00
Date: Tue, 07 Dec 1999 00:00
16 lines
1513 bytes
1513 bytes
Jud McCranie wrote: > Something that is equivalent to the UNTIL condition is "until > false". > Jud McCranie And? Alex -- ** Pepsi Cola and Animal protection ** || Demonstration gegen Pelzhandel am 11.12.1999 ** http://www.pepsibloodbath.com/ ** || http://www.vgt.at/grossdemo.htm/ Author of the free Chatsystem PINO! || Website: http://www.alcomp.net Available at http://pino.cjb.net || Chat : pinochat.dhs.org:8080
Re: Random function - PASCAL
Author: Frederic Bonroy
Date: Tue, 07 Dec 1999 00:00
Date: Tue, 07 Dec 1999 00:00
9 lines
1244 bytes
1244 bytes
Alexander Mueller wrote: > Jud McCranie wrote: > > Something that is equivalent to the UNTIL condition is "until > > false". > > And? Well, it's IMHO more elegant.
Re: Random function - PASCAL
Author: Jud McCranie
Date: Tue, 07 Dec 1999 00:00
Date: Tue, 07 Dec 1999 00:00
9 lines
1250 bytes
1250 bytes
Frederic Bonroy <fbonroy@mail.dotcom.fr> wrote: >> > Something that is equivalent to the UNTIL condition is "until >> > false". >Well, it's IMHO more elegant. And perhaps less confusing. Jud McCranie
Re: Random function - PASCAL
Author: Marek M�nd
Date: Tue, 07 Dec 1999 00:00
Date: Tue, 07 Dec 1999 00:00
9 lines
1163 bytes
1163 bytes
>repeat until false >repeat until 1=2 Cool, never had thought in this way ... -- Marek M�nd marek.mand@ttu.ee
Re: Random function - PASCAL
Author: Robert Rossmair
Date: Wed, 08 Dec 1999 00:00
Date: Wed, 08 Dec 1999 00:00
23 lines
1476 bytes
1476 bytes
Hi Jud,
you wrote:
> >> Something that is equivalent to the UNTIL condition is "until
> >> false".
> >
> >And?
>
> And that's it - nothing else. The neatest way to do it.
I consider the following to be neater than neatest :)
const
SystemDown = False;
...
repeat
DoSomething;
until SystemDown;
Greetings, Robert
Re: Random function - PASCAL
Author: Jud McCranie
Date: Wed, 08 Dec 1999 00:00
Date: Wed, 08 Dec 1999 00:00
23 lines
1388 bytes
1388 bytes
Robert Rossmair <Robert.Rossmair@t-online.de> wrote: >I consider the following to be neater than neatest :) > >const > SystemDown = False; > > ... > > repeat > DoSomething; > until SystemDown; Or how about constant EndOfTime = false; repeat until EndOfTime; Jud McCranie
Re: Random function - PASCAL
Author: Osmo Ronkanen
Date: Wed, 08 Dec 1999 00:00
Date: Wed, 08 Dec 1999 00:00
21 lines
1543 bytes
1543 bytes
In article <384DC718.F5C9C609@t-online.de>, Robert Rossmair <Robert.Rossmair@t-online.de> wrote: > >I consider the following to be neater than neatest :) > >const > SystemDown = False; > > ... > > repeat > DoSomething; > until SystemDown; I hope that really was a joke. things like Repeat until false may seem strange for a novice but someone who knows the language knows what it means. It might be better to use While: While true do begin... end; At that way one immediately sees that it is an eternal loop. Osmo
Re: Random function - PASCAL
Author: Alexander Mueller
Date: Wed, 08 Dec 1999 00:00
Date: Wed, 08 Dec 1999 00:00
10 lines
1451 bytes
1451 bytes
Thats funny. I just wanted to show an example about how to get a random list and this started a thread with 11 postings :) till now. Alex -- ** Pepsi Cola and Animal protection ** || Demonstration gegen Pelzhandel am 11.12.1999 ** http://www.pepsibloodbath.com/ ** || http://www.vgt.at/grossdemo.htm/ Author of the free Chatsystem PINO! || Website: http://www.alcomp.net Available at http://pino.cjb.net || Chat : pinochat.dhs.org:8080
Re: Random function - PASCAL
Author: Arno Fleck
Date: Wed, 08 Dec 1999 00:00
Date: Wed, 08 Dec 1999 00:00
22 lines
1422 bytes
1422 bytes
Hi ! > const > SystemDown = False; > > ... > > repeat > DoSomething; > until SystemDown; And here's another possibility: ;-) WHILE True DO DoSomething; Bye, Arno -- http://afleck.home.pages.de (English and German) Software, Links, C&C, Chartbreaker and more http://pangea.home.pages.de (German only) Mach mit bei einem Spiele-Projekt im Internet
Re: Random function - PASCAL
Author: Hermann Kraus
Date: Fri, 10 Dec 1999 00:00
Date: Fri, 10 Dec 1999 00:00
22 lines
1434 bytes
1434 bytes
Arno Fleck schrieb: > Hi ! > > > const > > SystemDown = False; > > > > ... > > > > repeat > > DoSomething; > > until SystemDown; > > And here's another possibility: ;-) > WHILE True DO DoSomething; > But how to stop then programm? Hermann
Re: Random function - PASCAL
Author: Ars�ne von Wyss
Date: Fri, 10 Dec 1999 00:00
Date: Fri, 10 Dec 1999 00:00
17 lines
1776 bytes
1776 bytes
Hermann Kraus <hnkraus@be-ne.de> schrieb in im Newsbeitrag: 385107DE.9C386932@be-ne.de... > Arno Fleck schrieb: > > And here's another possibility: ;-) > > WHILE True DO DoSomething; > > But how to stop then programm? Using Halt (terminate program), Exit (terminate current procedure/function) or Break (exit loop) in the "infinite" loop. -- Ars�ne von Wyss - avonwyss@gmx.net Pascal, Delphi & Personal stuff: http://bsn.ch/avonwyss Programming Contest Problems Archive: http://bsn.ch/contest Webmaster von Roger's Equine Pages: http://bsn.ch/pferde
Re: Random function - PASCAL
Author: Dr John Stockton
Date: Sat, 11 Dec 1999 00:00
Date: Sat, 11 Dec 1999 00:00
26 lines
2314 bytes
2314 bytes
JRS: In article <38515400@news.datacomm.ch> of Fri, 10 Dec 1999
18:47:01 in news:comp.lang.pascal.borland, Ars�ne von Wyss
<avonwyss@gmx.net> wrote:
>Hermann Kraus <hnkraus@be-ne.de> schrieb in im Newsbeitrag:
>385107DE.9C386932@be-ne.de...
>> Arno Fleck schrieb:
>
>> > And here's another possibility: ;-)
>> > WHILE True DO DoSomething;
>>
>> But how to stop then programm?
>
>Using Halt (terminate program), Exit (terminate current procedure/function)
>or Break (exit loop) in the "infinite" loop.
Admittedly inelegant ; but, in addition,
while true do begin
Write(' x? ') ; Readln(x)
process(x) end ;
can be stopped with ^C; and that's adequate for a Noddy test program.
--
� John Stockton, Surrey, UK. jrs@merlyn.demon.co.uk Turnpike v4.00 MIME. �
Web <URL: http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper 4-line sig. separator is as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads