RandomSeeding{...}

02/22/2012 17:42 bryce16#1
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?:confused:

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
02/22/2012 18:24 pro4never#2
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
02/22/2012 18:24 I don't have a username#3
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.
02/22/2012 19:34 bryce16#4
Interesting...Both you're responses helped me understand this better +1 for you two. I'll take your suggestions into consideration, Thanks!
02/23/2012 19:51 turk55#5
this post : [Only registered and activated users can see links. Click Here To Register...]
and
this post : [Only registered and activated users can see links. Click Here To Register...]

should help you
03/09/2012 00:15 bryce16#6
Quote:
Originally Posted by turk55 View Post
this post : [Only registered and activated users can see links. Click Here To Register...]
and
this post : [Only registered and activated users can see links. Click Here To Register...]

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 .......).
03/09/2012 07:37 I don't have a username#7
Oh you mean the password seed packet?

It's the client who requests that before it will send any packets to the server.
03/09/2012 21:39 bryce16#8
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.
03/09/2012 22:27 Spirited#9
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!
03/09/2012 22:48 bryce16#10
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? .-.
03/14/2012 10:11 I don't have a username#11
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.