Ariane Soft PPL2 Pocket Programming DataMite
Old 08-14-2007, 07:38 AM
Kevin Johnson Kevin Johnson is offline
Join Date: Jul 2007
Posts: 35
Default Timing Delays

here's is what my code is supposed to do:

- generate a series of random numbers (0 and 1)
- the number in this series must be set to a specific number per second

some computers are faster than others, so i need to put some kind of delay loop. however, i need to make sure that a particular system is capable of produceing a set number of RNG numbers per second (e.g. 9600 bits / second). I have most of it worked out already, but i'm a little confused on how i can finish this up.
One thing that i want to also mention is that the RNG data (bits) will be corrolated with their time domain and fed into a spreadsheet document (.CSV) for further analysis. Any ideas?

f$ = fopen("test.txt", "w"

SampleRate$ = 1000;

for (x$, 1, 25)
ones$ = 0;
zero$ = 0;
// Generate a Series of Random Numbers
for (SampleCount$, 1, SampleRate$)

rand$ = rand(); // Init the RNG
random$ = random(2); // Generate the RNG digit

if (Random$ == 1)
ones$ = ones$ + 1;
zero$ = zero$ + 1;


Deviation$ = SampleRate$ / 2;
Mean$ = ones$ / SampleRate$;

Zscore$ = (ones$ - Mean$) / Deviation$;

writestring(f$, Zscore$);


Reply With Quote
Old 08-14-2007, 03:59 PM
Posts: n/a

Here is something that you will be able to use in PPL version 1.30 later this week:


// Returns counts per second computer can process
f$ = LargeInt(PC$);

// Counter
old$ = LargeInt(PC$);
until (LargeInt(PC$) - old$ >= f$ * 10);

// Ten seconds have passed!

ToLargeInt(1000, PC$);

This will calculate the number of cycles per second based on the speed of the CPU. In this example I let 10 seconds pass before continuing. You can use the frequency value to do some elaborate calculations, I use it with the GameAPI to make sure the games runs at the same speed on different machines.
Reply With Quote
Old 09-25-2007, 07:36 PM
Kevin Johnson Kevin Johnson is offline
Join Date: Jul 2007
Posts: 35

The only problem i have with this, is that the code doesn't seem very portable. Which is what i usually try to do with all of my programming projects. At least as much as possable.
What i'm really looking for is just a way to produce a 1200 RNG digits every second. And making sure that can happen on any computer my program is run on.
Reply With Quote
Old 09-25-2007, 08:04 PM
Posts: n/a

It is the most portable solution on Windows and Windows Mobile.

The QueryPerformanceFrequency returns a value that is unique to the speed of each machine or device. This way you can have a program running at the same speed on all devices including the desktop PC no matter what its CPU speed is.
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) ArianeSoft Inc.
Copyright © 2009 - All rights reserved
Web Design by BR Web Consulting Ltd