Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #29696
| Newsgroups | comp.lang.javascript |
|---|---|
| Date | 2016-02-26 05:15 -0800 |
| References | <7ccc75ef-3d8a-498b-823e-574b94799162@googlegroups.com> <25d67df9-f31a-4c9b-b53e-2a5f3d1d2506@googlegroups.com> |
| Message-ID | <f9846150-9602-4664-91d0-3ec40706eb01@googlegroups.com> (permalink) |
| Subject | Re: Exhausting link pairs between nodes using math.rand in a uniform network. |
| From | jonas.thornvall@gmail.com |
Den fredag 26 februari 2016 kl. 14:13:07 UTC+1 skrev jonas.t...@gmail.com:
> Den fredag 26 februari 2016 kl. 13:51:05 UTC+1 skrev jonas.t...@gmail.com:
> > A short snippet to exhaust possible links.
> > Solution is close so close i thought it was correct, but when i set to correct restriction upon the random, the loop never end, and my understanding of firefox debugger to shallow to track down the loop error.
> >
> > If anyone can see why it does not run thru with correct math rand restrictions tell me.
> >
> > Sometimes one really would love a Turbo pascal debugger, because with it one could follow code execution and detect values that loop.
> >
> > <script type="text/javascript">
> > arr = new Array();nodes = 9; links = 4;
> > for(k = 0; k < nodes; k ++ )
> > {
> > arr[k] = { nroflinks : 0, nodelinks : "" };
> > }
> > createLinks();
> >
> > function createLinks()
> > {
> > i = 0;
> > j = 0;
> > temp = new Array();
> >
> > while(i < nodes)
> > {
> > //This see so that links already generated accounted for if one link than j=0 and so on.
> > j = arr[i].nroflinks;
> > while(j < links)
> > {
> > dublett = false;
> > //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> > //Why?? aLink = Math.floor(Math.random() * (nodes - i)) + i;
> > aLink = Math.floor(Math.random() *nodes) ;
> > for(k = 0; k < temp.length; k ++ )
> > {
> > if(aLink == temp[k])
> > {
> > dublett = true; document.write("already in list " );
> >
> > }
> > }
> >
> > if(aLink == i){dublett=true;}
> > document.write(dublett,"New Link-->", aLink, "<br>");
> > if(dublett == false )
> > {
> > temp[j] = aLink;
> > arr[i].nodelinks += aLink + ",";
> > arr[aLink].nodelinks += i + ",";
> > document.write(i, "<--->", arr[i].nodelinks, "<br>");
> > arr[i].nroflinks ++ ;
> > arr[aLink].nroflinks ++ ;
> > j ++ ;
> > }
> > }
> > document.write("<P>" );
> > i++;
> > }
> > }
> > </script>
>
> Well spotted an error, i probably need something else than storing links than in the string nodelinks. Because the comparisson do not account for links already written to node.
>
> So rather than the string nodelinks temp arr should be nodelinks. But i have no idea how to declare an array within array.
I rephrase the question how do i make nodelinks an array rather than a string.
for(k = 0; k < nodes; k ++ )
{
arr[k] = { nroflinks : 0, nodelinks : "" };
}
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 04:50 -0800
Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 05:13 -0800
Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 05:15 -0800
Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 05:22 -0800
Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 05:27 -0800
Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 05:49 -0800
Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 06:05 -0800
Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 07:30 -0800
Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 07:35 -0800
Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 07:41 -0800
Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 07:58 -0800
Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 09:10 -0800
Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 09:36 -0800
Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 10:42 -0800
Re: Exhausting link pairs between nodes using math.rand in a uniform network. "Chris M. Thomasson" <nospam@no-spam.ws> - 2016-02-26 12:13 -0800
Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 14:52 -0800
Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-27 13:27 -0800
Re: Exhausting link pairs between nodes using math.rand in a uniform network. Luuk <luuk@invalid.lan> - 2016-02-28 17:36 +0100
Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-29 11:24 -0800
Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-29 11:58 -0800
Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-29 13:52 -0800
csiph-web