routing - How does the "Random Walk" algorithm work? -


the algorithm below written in pseudocode , simplicity storage of actual route in data structure not included.

lengthfromsrc   = 0;     lengthfromdest  = 0;     totalnumberhops = 0;      x = src;  /*last node visited random walk starting @ src;*/     y = dest; /*last node visited random walk starting @ dest;*/     /* randomly select route length */     {         length = rand( ) % max;         while( length < min );       while( totalnumberhops < length ) {                   next = toss coin pick random walk src or dest;        if( next == randwalkfromsrc ) {       z = randomly select adjacent node x;       totalnumberhops = 1 + lengthfromsrc + lengthfromdest                             + shortest-path z y;        if( totalnumberhops > length )             break;       x = z;            /*include node in route*/               store x in route data structure            lengthfromsrc++;       }       else {  /* next = randwalkfromdest */       z = randomly select adjacent node y;       totalnumberhops = 1 + lengthfromsrc + lengthfromdest                             + shortest-path z x;        if( totalnumberhops > length )             break;       y = z;                           store y in route data structure            lengthfromdest++;        }       } 

would give me brief analysis of algorithm/or walk me through code, understand better? main problem understanding first part:

      {           length = rand( ) % max;           while( length < min );             while( totalnumberhops < length ) 

ps: source http://www.onion-router.net/archives/route/

i'd code missing } (although pseudo-code, goes really)

do {     length = rand() % max; } while( length < min ); 

rand() a function c++ generates integer between 0 , @ least 32767 (although, purposes of this, think should assume maximum number can generated greater max).

% max gives remaining of number divided max, length between 0 , max-1 (inclusive).

then repeat until length >= min, so, @ end, length between min , max-1 (inclusive).

we can avoid loop code:

length = min + rand() % (max - min); 

or, since pseudo-code:

length = random number in range [min, max) 

the rest of code generates 2 paths @ same time source , destination, , stops when linking them (using shortest possible path) result in walk longer length.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -