TechTalkz.com Logo Ask the Experts!

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Apple

TML Pascal II Random Number

Apple

 
 
Thread Tools Display Modes
Unread 26-11-2007, 09:32 AM   #1
limtc
Guest
 
Posts: n/a
TML Pascal II Random Number

Hi,

Anybody still using TML Pascal II (or Complete Pascal) here? I just
came back to do programming on TML Pascal, and I likes it a lot!

However, I have a question, how do you do a random number (either 0 to
1, or 0 to x where x is an integer) in TML Pascal?

I see someone ask the same question but there is no reply.

Thye Chean


Sponsored Links
 
Unread 26-11-2007, 09:32 AM   #2
limtc
Guest
 
Posts: n/a
Re: TML Pascal II Random Number

I have an answer for myself, but not sure whether this is the best
solution for TML Pascal. Any suggestion appreciated.

I found that the Random function is actually provided by QuickDraw,
and it also has a SetRandSeed function. So I use the GetTick function
in the MiscTool and do this:

SetRandSeed(GetTick)
x := abs(Random);

This will give me a number between 0 to 32768, but then I have to
divide down to the range that I really wanted. Looks like a hardway to
do something simple, but is there a better method?


 
Unread 26-11-2007, 09:32 AM   #3
Michael J. Mahon
Guest
 
Posts: n/a
Re: TML Pascal II Random Number

limtc wrote:
> I have an answer for myself, but not sure whether this is the best
> solution for TML Pascal. Any suggestion appreciated.
>
> I found that the Random function is actually provided by QuickDraw,
> and it also has a SetRandSeed function. So I use the GetTick function
> in the MiscTool and do this:
>
> SetRandSeed(GetTick)
> x := abs(Random);
>
> This will give me a number between 0 to 32768, but then I have to
> divide down to the range that I really wanted. Looks like a hardway to
> do something simple, but is there a better method?


The ways of generating pseudorandom numbers is legion--and many
of them are of low quality and/or low performance.

If you are re-seeding from a timer value at each call, then you are
1) getting a *really* random first value, and 2) getting non-random
values for subsequent calls unless some indetermnate time event occurs
between calls, like a user interaction.

If you divide the number to get a value in a particular range, use
the remainder, not the quotient, since the remainder changes most
rapidly.

If you prefer pseudorandom numbers, so that you can re-run a program
and reproduce its behavor deterministically, you should Google for
"pseudorandom number generator" and program one that fits your needs.
A good generator will only be one or two lines of code.

You must remember that pseudorandom numbers are not actually random
numbers. As John von Neumann famously said, "Anyone who uses arithmetic
methods to produce random numbers is in a state of sin." ;-)

-michael

NadaNet file server for Apple II computers!
Home page: http://members.aol.com/MJMahon/

"The wastebasket is our most important design
tool--and it's seriously underused."
 
Unread 26-11-2007, 09:32 AM   #4
limtc
Guest
 
Posts: n/a
Re: TML Pascal II Random Number

Sponsored Links
My latest answer:

SetRandSeed(GetTick);
x := Random mod y;

This will return an answer between 0 to y-1, which is what I want. Now
everything looks simple enough.


Sponsored Links
 
 

Thread Tools
Display Modes



< Home - Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT. The time now is 10:07 PM.


vBulletin, Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © 2005-2016, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional