Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Randomize timer in function

Author
Message
Jac
21
Years of Service
User Offline
Joined: 9th Nov 2003
Location:
Posted: 31st Jul 2005 13:04
Hi,

Just a quick question. I've randomized the timer at the top of my main code. When I creat a function will the time remain ramdom or do I have to randonize it again in the function.

Thanks in advance,

JC

These are not the droids you are looking for.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 31st Jul 2005 14:32
You only need to do it once. From that point on, your numbers will be random.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins and source code http://www.matrix1.demon.co.uk
Jac
21
Years of Service
User Offline
Joined: 9th Nov 2003
Location:
Posted: 6th Aug 2005 11:03
Thanks,

I thought as much from the way the code was behaving, just wanted to make sure. Find it helps when I have a full understanding of the code I write.

Sorry for the late reply been caught up in with other other stuff for a few days.

JC

These are not the droids you are looking for.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 6th Aug 2005 21:47
One Randomize Timer() will put you in a different position in the series of random numbers. They will actually come out in the same sequenmce, you just won't know where you started.

If you want a more random order, you need to randomize timer() more often

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 7th Aug 2005 00:16
BatVink:

Quote: "If you want a more random order, you need to randomize timer() more often"


Not so sure about that actually...

I can't see how re-seeding will make any difference. How can you have more random than 'random'?

If it's done at the start of the program, every time it is run, the sequence will be different, so for example, NPC's won't start in the same random locations.

Re-seeding in the program multiple times isn't going to have any noticable effect at all as the sequence of random numbers is already 'random' from the first seed.

TDK_Man
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 7th Aug 2005 00:53 Edited at: 7th Aug 2005 00:55
It's a predefined series of 32768 numbers. Randomizing simply puts the pointer in a different starting position. But position 1 will always contain the same number, and so on.

So yes, for many games, randomizing once is fine. The chances of someone remembering a particular part of the sequence is minimal. But it becomes more important to randomize more frequently in games such as cards, especially in a competitive arena. If you were to play cards for an hour or so, it's quite possible to start to recognise particular sequences, especially if you are simply remembering the position of Aces for example.

Dejunai
19
Years of Service
User Offline
Joined: 19th Jul 2005
Location: Mentally: Manhattan; Physically: LA -doh
Posted: 7th Aug 2005 02:46 Edited at: 7th Aug 2005 02:56
It is very simple to write a function
that will ~hopefully~ keep things more random.



In some of my code I truely abuse the RND() function.
As such I was seeing patterns ( I might have been high )
if I only called "RANDOMIZE" once at the begining of my code.

When I substituted the above snippet for the RND() function,
either I had sobered up, or it was more random than before.
Furthermore I notice zero decrease in FPS.

I suppose depending on your code, the actual underlying features
of the "RANDOMIZE" command, the interval with which you call
your new "myRandom" function, you may ultimately see a pattern,
or have a decrease in Frame Rate.

If such were true you might optionally call "randomize timer()"
and the begining or end of your "heartbeat" loop. This would
call the command the exact same number of times that your
current/real FPS is functioning at.

If you were still seeing a decrease in functionality of your
application, compared to calling it once at the begining of the
application, you could modify it in such a way to be conditional.

Such as:


Which in the above example would only execute the "RANDOMIZE"
command every 2 seconds. You can simple adjust <deltatimer>
to your needs. <deltatimer> is ( ofcourse ) in miliseconds.

No one should argue relying on "RND()" alone, is ill-advised.
You will likely see patterns repeat on every execution of your
application. And personally IMHO so is the use of
"randomize timer()" if it is only called once.

But that is just my opinion and my two cents...



============ : Windows 200 SP4+, 3.2GHz Hyperthreaded
-Dejunai ............: 2GB RAM, nVidia 6600 256MB AGP 8x
============ : AC'97 basic A-Bit Motherboard Audio ( drivers always Maintained )
Jac
21
Years of Service
User Offline
Joined: 9th Nov 2003
Location:
Posted: 7th Aug 2005 10:46
Wow.

Thanks BatVink, TDK and Dejunai. I know have a fuller understanding od how to create random numbers.

There are three aims for my current project. Create a full complete game (however simple), learn lots of new stuff about programing (I've never programed before) and naturaly have fun.

Looking at the information given I think one randomize timer() will be enough but I'll keep whats said in mind for future projects.

JC

These are not the droids you are looking for.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 7th Aug 2005 15:14
Dejunai, I'm glad someone else sees the patterns . By the way, I've never been high in my life, and I see them

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 7th Aug 2005 17:01
I have to admit that I was only thinking about it from the perspective of using RND to control small aspects of the game - like randomly positioning objects.

If you were using it to generate random patterns for graphics or creating a card game then yes, I can appreciate the lack of 'real' randomness could show up.

I therefore retract my statement - with an apology for ever doubting you!

TDK_Man
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 8th Aug 2005 12:40
Using a number you define (rather than using timer() ) will always be the same pattern which is good for encryption routines. You can use the seed number as a password to encrypt/unencrypt text.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 9th Aug 2005 01:16
Quote: "You can use the seed number as a password to encrypt/unencrypt text. "


Sure can...check out bvEncrypt, my free registration code maker. You enter a seed to ensure you can use the same routine, but make unique codes for each user.

http://darkbasic.biglaugh.co.uk

Login to post a reply

Server time is: 2024-11-12 03:06:45
Your offset time is: 2024-11-12 03:06:45