Register for your free account! | Forgot your password?

You last visited: Today at 00:27

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



RandomSeeding{...}

Discussion on RandomSeeding{...} within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
bryce16's Avatar
 
elite*gold: 0
Join Date: Oct 2010
Posts: 47
Received Thanks: 3
Question RandomSeeding{...}

I have a question for those with more experience with C# development than I do, Iv'e noticed something on many sources I cannot seem to piece together.
Can someone explain to me/community of CO what these following codes do and how it benefits a source?

Code:
public static int RandomSeed = 0;
Code:
ServerBase.Kernel.Random = new Random(RandomSeed);
Code:
RandomSeed = Convert.ToInt32(DateTime.Now.Ticks.ToString().Remove(DateTime.Now.Ticks.ToString().Length / 2
bryce16 is offline  
Old 02/22/2012, 18:24   #2
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,380
Seems like a horrible way to do it but they are setting up a random number generator (system.random) with a seed based on system time... They are doing it in a poor way though because..

1: its auto set to seed with system time if you dont enter any parameter
2: needlessly wasteful math to pull system time to seed with... Use environment.tickcount or native.timegettime if you wanted to manually seed
pro4never is offline  
Thanks
1 User
Old 02/22/2012, 18:24   #3
 
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
Code:
public static int RandomSeed = 0;
This is the seed, whom the Random is generated out of. You have to make a seed to generate a random number out of and the seed will change for every instance. It does not benefit anything and the seed is generated no matter what, if you do not give the Random a seed, then it will create is own using Environment.TickCount I think or something among those lines.

Code:
ServerBase.Kernel.Random = new Random(RandomSeed);
This is just creating a new instance of the Random with the RandomSeed send to the constructor.

Code:
RandomSeed = Convert.ToInt32(DateTime.Now.Ticks.ToString().Remove(DateTime.Now.Ticks.ToString().Length / 2
This is just a bunch of useless code IMO. You could create a seed much easier or don't do it at all, because it's a bad way to do it, why do you want to get the tickcount, convert it to a string, remove some characters within it dividing the length with 2 and then convert it back to an int. A lot of code for such a simple task.
I don't have a username is offline  
Thanks
1 User
Old 02/22/2012, 19:34   #4
 
bryce16's Avatar
 
elite*gold: 0
Join Date: Oct 2010
Posts: 47
Received Thanks: 3
Interesting...Both you're responses helped me understand this better +1 for you two. I'll take your suggestions into consideration, Thanks!
bryce16 is offline  
Old 02/23/2012, 19:51   #5
 
turk55's Avatar
 
elite*gold: 130
Join Date: Oct 2007
Posts: 1,655
Received Thanks: 705
this post :
and
this post :

should help you
turk55 is offline  
Old 03/09/2012, 00:15   #6
 
bryce16's Avatar
 
elite*gold: 0
Join Date: Oct 2010
Posts: 47
Received Thanks: 3
Quote:
Originally Posted by turk55 View Post
this post :
and
this post :

should help you
Ah yes, I took a careful look over those comments so thank you for the help.
I realized that RandomSeeding on this program.cs is what allows others to login. Strange enough it has nothing to do with the posts above. So I'm a bit confused at the moment on that and if I need to make the program.cs read the ThreadSafe file(using .......).
bryce16 is offline  
Old 03/09/2012, 07:37   #7
 
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
Oh you mean the password seed packet?

It's the client who requests that before it will send any packets to the server.
I don't have a username is offline  
Thanks
2 Users
Old 03/09/2012, 21:39   #8
 
bryce16's Avatar
 
elite*gold: 0
Join Date: Oct 2010
Posts: 47
Received Thanks: 3
Quote:
Originally Posted by I don't have a username View Post
Oh you mean the password seed packet?

It's the client who requests that before it will send any packets to the server.
Yes it seems to be the password seed packet.("Invalid Password Please Try Again")
Is there any way I could possibly get rid of this RandomSeeding and construct a more efficient way of Password Seeding? If so, A demonstration would be very helpful.
bryce16 is offline  
Old 03/09/2012, 22:27   #9
 
Spirited's Avatar
 
elite*gold: 12
Join Date: Jul 2011
Posts: 8,283
Received Thanks: 4,191
Quote:
Originally Posted by bryce16 View Post
Yes it seems to be the password seed packet.("Invalid Password Please Try Again")
Is there any way I could possibly get rid of this RandomSeeding and construct a more efficient way of Password Seeding? If so, A demonstration would be very helpful.
There are demonstrations found in every source running on patch 5176 or above.
Just download one, read it, and you'll be set. Good luck!
Spirited is offline  
Old 03/09/2012, 22:48   #10
 
bryce16's Avatar
 
elite*gold: 0
Join Date: Oct 2010
Posts: 47
Received Thanks: 3
Quote:
Originally Posted by Fаng View Post
There are demonstrations found in every source running on patch 5176 or above.
Just download one, read it, and you'll be set. Good luck!
Whoa, really? In that case, here I go!(search/downloads) thanks =p

UPDATE: I managed to get rid of the RandomSeeding and use Project Manifests Random code in attempt to login with it, It was a success. I still wonder if the main server initialization file should always load the ThreadSafeWrapper or not? .-.
bryce16 is offline  
Old 03/14/2012, 10:11   #11
 
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
Quote:
Originally Posted by bryce16 View Post
I still wonder if the main server initialization file should always load the ThreadSafeWrapper or not? .-.
For the random? If you use a random other places, then yes. I most likely assume you do, so yes.
I don't have a username is offline  
Reply




All times are GMT +1. The time now is 00:28.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.