Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Sep 18, 2019 2:07 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 52 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Mon Nov 12, 2012 6:54 pm 
Offline

Joined: Tue Mar 23, 2010 8:44 pm
Posts: 673
Maybe I'm not using the RS randomizer correctly but I generated supposedly 1,000 random numbers using RS and what I got was not very random.

Almost all of the returned numbers where the same length in digits and every single 'random' number ended in 0. I did not test for any collision occurances but it seems to be far from random.

Copy and paste the code, try it yourself :

Dim r as New Random
dim ID as string
dim counter as integer

For counter = 1 to 1000
ID =Str(r.InRange(0,1000000000))
window1.textarea1.text = window1.textarea1.text+ ID +chr(13)
next


I didn't read the documentation on the random function so maybe I did something wrong when generating the random numbers?

I expected to get a wide range of numbers varying in digit length and ending values but that is not what happened.


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Mon Nov 12, 2012 6:59 pm 
Offline
Site Admin
User avatar

Joined: Tue May 06, 2008 1:07 pm
Posts: 1464
Location: NotEvenOnTheMap, CT
You should select a random seed as well.

_________________
Thom McGrath - @tekcor
Web Framework Architect, Real Software, Inc.


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Mon Nov 12, 2012 7:02 pm 
Offline
User avatar

Joined: Sun Oct 28, 2012 4:54 am
Posts: 264
Location: Herts, UK
Now that is an interesting and a valid observation :?:

_________________
Real Studio 2012 R2
SysInfo
BackTrack Linux/BackBox Linux/Debian Lenny/Windows 7/Windows 8/OpenWRT/OpenBSD
& Yes it's me in the Avatar


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Mon Nov 12, 2012 7:06 pm 
Offline

Joined: Tue Mar 23, 2010 8:44 pm
Posts: 673
Something goofy is going on here.

I assigned the seed to the increasing counter so the seed changes (increases) with each iteration and here's a snippet of what I got :

125905180
171446000
216986820
262527640
308068460
353609280
399150100
444690920
490231740
535772560
581313380
626854200
672395020
717935840
763476660
809017480

Then I changed the seed to be the Val of ID (on the next pass) and this is a snippet of what I got :
320536740
786846240
790636240
498436240
894436240
614436240
14436240
14436240
14436240
14436240
14436240
14436240
14436240
14436240

Is it possible it's a bug in then random function when passed a large number like I've passed it?

Can you provide a good random code snippet that provides good randomization results with varying digit lengths with a random seed every iteration?


Last edited by J.Sh3ppard on Mon Nov 12, 2012 8:27 pm, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Mon Nov 12, 2012 8:10 pm 
Offline
Site Admin
User avatar

Joined: Tue May 06, 2008 1:07 pm
Posts: 1464
Location: NotEvenOnTheMap, CT
You want to use a single Random object for the entire project, and don't change the seed so often. When you do that, the results are much more normal. Here are 100 random numbers between 0 and 1,000,000,000. I'll admit the fact that they all end in 0 is interesting.

529887380
523689800
459776630
751514070
945552320
874705580
372432050
60913930
564737420
142172720
166054030
126259550
865791480
602456020
928143370
417707730
719447300
39184280
769944870
659239270
345941680
338770300
548367330
324978970
593735420
119530880
173503550
913115630
627833320
642406820
109750330
244757500
774644880
298334680
758111310
509625380
455177700
329883280
702315330
763229260
327966680
470139400
636193430
762452980
628244460
230700480
158843850
576551580
295998880
335183160
105128030
764367300
110308980
449079280
997446610
322425580
916161000
35691880
209195430
122311060
750144380
392551200
502301530
747059030
521703910
820038590
578149900
87775280
542952980
872836260
575151590
338380850
666347530
136486930
772680360
535133340
163377800
394078280
552922130
129473710
425472590
760655750
865783780
630151080
740460060
189539340
186985950
509411530
425572530
461264410
670459840
792770900
542915280
935466480
437768010
184827040
706530950
526569540
104719440
192494720

_________________
Thom McGrath - @tekcor
Web Framework Architect, Real Software, Inc.


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Mon Nov 12, 2012 8:27 pm 
Offline

Joined: Tue Mar 23, 2010 8:44 pm
Posts: 673
Definitely seeing "RAINMAN" type patterns here.

Definitely Charley.

Charley Babbit.

YeeeAHHH!

:)


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Mon Nov 12, 2012 8:39 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
As Thom said earlier, just have the server increment an integer. Zero chance of duplicates. Integrate it into the protocol like he said and you're golden.


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Mon Nov 12, 2012 10:15 pm 
Offline

Joined: Tue Mar 23, 2010 8:44 pm
Posts: 673
timhare wrote:
As Thom said earlier, just have the server increment an integer. Zero chance of duplicates. Integrate it into the protocol like he said and you're golden.


Ummmmm, not quite. :)

You'd better code to reset your ever increasing integers or you'd better be prepared to crash or bug out and upset users at some point.

The highest integer RS will handle correctly (at least right now) is just over 2 billion :
2,147,483,647.

That means if you're not resetting your ever increasing unique integer IDs you will get really screwed because RS yields different wacky results for integers higher than that.

Try this :
dim thenumber as integer = 2147483647 'results in correct value :2147483647

//bugs - decomment the following to see what happens when the integer is >2147483647

'dim thenumber as integer = 2147483648 'BUG or higher results in -2147483648
'dim thenumber as integer = 2200000000 'results in -2094967296
'dim thenumber as integer = 2399999999 'results in -1294967297
'dim thenumber as integer = 9999999999 'results in 1410065407

// and so on.

// if you were using this unique ID system as suggested without resetting the integer value you'd be really screwed !

window1.textarea1.text=str(thenumber)


If you don't think your ever increasing counter will ever hit the magic 2 billion number then you'd probably be ok. But over time if you think you're going to hit over that 2.1 billion mark you'd better be resetting your user ID number and you'd probably only be safe to do this when zero users are connected, IF you get that chance. If you have a popular service or a 24hour based one you may never get that chance to peacefully reset due to users being online.

Remember Y2k? Code smart from the beginning and you won't find yourself in hot water.

So using my unique UserID + IP identifier doesn't have all of these issues but choose your own poison.

Yah, over time you'll learn to hate me and my posts :)


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Mon Nov 12, 2012 10:35 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
No. It merely "rolls over" in a predictable, orderly way. There would have to be 4 billion connections before you got back to zero, and by that time, the first connection would have gone away.


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Mon Nov 12, 2012 10:39 pm 
Offline

Joined: Tue Mar 23, 2010 8:44 pm
Posts: 673
timhare wrote:
No. It merely "rolls over" in a predictable, orderly way. There would have to be 4 billion connections before you got back to zero, and by that time, the first connection would have gone away.


LOL.

It is so much easier to do it my way than deal with all that nonsense.

Then what happens when RS goes 64 bit and the numbers change again?

Recode or will it be fine....

I don't believe for one moment those numbers are correctly randomized so I'm a bit skeptical about the incremental method. I know it can work out fine but I see other benefits to doing it my way.

The odds of all those numbers randomly ending in 0 isn't realistic. I did it with over 1,000 numbers and they all ended in zero. It's not real randomization in my opinion.
Something's wrong.



:)


Last edited by J.Sh3ppard on Mon Nov 12, 2012 10:43 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Mon Nov 12, 2012 10:40 pm 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
If 2.1 billion connections is a realistic problem, then use a wider integer type (UInt64 has a range of 0 to >18 quintillion.)

_________________
Boredom Software


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Mon Nov 12, 2012 10:41 pm 
Offline
Site Admin
User avatar

Joined: Tue May 06, 2008 1:07 pm
Posts: 1464
Location: NotEvenOnTheMap, CT
Unless you use an unsigned integer, or an unsigned 64 bit integer. Then you'll get 4,294,967,295 or 18,446,744,073,709,551,615 respectively. If you can use up 2^64 connections, bravo, you've created the next Facebook. And if you've done so without bothering to write 5 minutes worth of maintenance code, you're also insane.

Sheppard, you speak of collisions and edge-cases, but have repeatedly ignored my demonstrating an easily reproducible collision in your proposal. What I've proposed will fail under exceedingly rare and hard-to-acheive cases, yes, but yours will fail in normal use-case scenarios. I've been there, I've done that. I'm offering advice as an expert in the field, IP addresses are not good for unique identifiers. It has bitten me every single time. I've done this for years. I've done it wrong, and I've done it right. Our own internal orders app use to build an identifier based on the IP, port, and username. It still failed, just ask our customer service reps how many times a message would not get from one to another.

I'm not trying to give you a hard time, I'm just trying to help as somebody who has been down this road too many times to count.

_________________
Thom McGrath - @tekcor
Web Framework Architect, Real Software, Inc.


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Mon Nov 12, 2012 10:42 pm 
Offline

Joined: Tue Mar 23, 2010 8:44 pm
Posts: 673
charonn0 wrote:
If 2.1 billion connections is a realistic problem, then use a wider integer type (UInt64 has a range of 0 to >18 quintillion.)



Well that sounds better but I still prefer my way since it has other benefits.


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Mon Nov 12, 2012 10:42 pm 
Offline
Site Admin
User avatar

Joined: Tue May 06, 2008 1:07 pm
Posts: 1464
Location: NotEvenOnTheMap, CT
J.Sh3ppard wrote:
Then what happens when RS goes 64 bit and the numbers change again?

Nothing. A 64-bit app will still keep Integer as an alias for Int32.

_________________
Thom McGrath - @tekcor
Web Framework Architect, Real Software, Inc.


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket Example Project ActiveConnections
PostPosted: Mon Nov 12, 2012 10:46 pm 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
J.Sh3ppard wrote:
Well that sounds better but I still prefer my way since it has other benefits.

I'm not sure which benefits to which you refer.

_________________
Boredom Software


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 52 posts ]  Go to page Previous  1, 2, 3, 4  Next

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group