Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-22-2007, 06:59 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Random...

I remember a while ago Kai posted here about the random not being random. (http://forums.graalonline.com/forums...ad.php?t=44692)
What happens is that when random is used in a timeout, it forms a pattern, though it doesn't do this when used in for. So I made my own little graphing thing quickly and messed around with it.
It seems the pattern is ALWAYS the same(if the same values are entered), no matter how many times it's called. Though the beginning is always different, after a few it begins to fall back on what seems to be the same pattern. See in the animation, these are the separate graphs I made.


I guess this isn't really a tech support thing, but I noticed Stefan seems to be frequenting the tech support section a lot lately, so I really just want to know why this does this. And would it effect things like baddies using random functions to determine successful attacks or such likely scenarios? I could understand patterns emerging, but why the same pattern, each time, and why isn't the beginning part of the pattern?
Reply With Quote
  #2  
Old 05-22-2007, 07:34 PM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
To fix that there would have to be a way of reseeding the random generator, like the srand() function in C++. I found a fairly good explanation of why it's needed here: http://www.bergen.org/AAST/Projects/...son4/rand.html
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #3  
Old 05-25-2007, 01:55 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
:o
Reply With Quote
  #4  
Old 05-25-2007, 02:22 AM
Sum41Freeeeek Sum41Freeeeek is offline
Future Coder
Join Date: Feb 2004
Location: New York
Posts: 376
Sum41Freeeeek is on a distinguished road
Send a message via AIM to Sum41Freeeeek
that's why it's so easy to win chance events :P
__________________
Frankie Cassini: ex-Era LAT
Quote:
Originally Posted by brakk View Post
omg just go to your room and draw a pony then

**** the chicken wings!
Reply With Quote
  #5  
Old 05-26-2007, 12:46 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
There are special random generators, might work better:

PHP Code:
rand = new MRandomLCG(); // or MRandomR250();
rand.seed int(timevar2*1000000);
echo(
"random value: " rand.randint() @ ", " rand.randfloat());
rand.destroy(); 
Reply With Quote
  #6  
Old 05-26-2007, 05:14 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
You have to think, how can you get a random variable? Your computer drops a ball, andwhereever it lands? Nah. They have to have some sort of formula.
__________________
Reply With Quote
  #7  
Old 05-26-2007, 05:29 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Stefan strikes again.

There is no such thing as Random on the computer, its known as Pseudo-Random, in the Java source that is. Using the time (timevar2) as a seed is always best, because its never the same
__________________
Reply With Quote
  #8  
Old 05-26-2007, 06:16 AM
Deadly_Killer Deadly_Killer is offline
Registered User
Join Date: Feb 2002
Posts: 227
Deadly_Killer is on a distinguished road
Assuming you seeded every one second. :o
__________________
- Zidane / Zidaya
Reply With Quote
  #9  
Old 05-26-2007, 11:47 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Well for the seed i multiplied with one million, so its taking the micro seconds which should be random enough.
It is possible to switch the script-random() function to a better random generator, might be good to test those two other generators and see if they are better.
Reply With Quote
  #10  
Old 08-14-2007, 04:14 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by Stefan View Post
It is possible to switch the script-random() function to a better random generator, might be good to test those two other generators and see if they are better.
You should do that, if it hasn't been done yet. Has it?
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
Reply


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 +2. The time now is 07:54 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.