473,473 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

randomly created arraylist are not RANDOM

1 New Member
i am trying to implement GP , and have random initialization in arraylist , the code works fine in debug mode , but when i run it without debugging, all trees come out to be same ,
if i use message box to show these trees , code works fine again ...
i have become MAD in resolving this issue !!

create_rndtree(ref al[i],depth)
create_fixtree(ref al[i],depth);

trees are stored in al array of arralist , which is cleared first
below is the code for one of the functions

private void create_rndtree(ref ArrayList tree,int depth)
{
tree.Clear();
int dangling_limbs = 1;
int i;
Random random = new Random();
double rnd;
int rndint;
//ArrayList tree=new ArrayList( );
char[] function=new char[4];
function[0]='-';
function[1]='+';
function[2]='/';
function[3]='*';
int num_attrib=cols-1;//one column is for class
//now how to generate the tree
//int possiblenodes=(cols-1)+function.Length+rnd;
int maxdepth=depth;
int leaf_nodes=Convert.ToInt32(Math.Pow(2,maxdepth));
int nodecount=0;
for (int k=0;k<maxdepth;k++)
{
nodecount=nodecount+Convert.ToInt32(Math.Pow(2,k)) ;
}
int max_size=nodecount;
object[] leafs=new object[leaf_nodes];
leafs=title.Split(';');


for ( i = 0; (dangling_limbs > 0) && (i <= max_size) ; i++ )
{ /*chose function or terminal at random*/
rnd=random.Next(0,100);
rnd=rnd/100;

if( rnd > (double)(dangling_limbs*dangling_limbs+1)/(double)(max_size-i) )// what is this for ????
{
rndint=random.Next(0,4);
tree.Add(Convert.ToString(function[rndint]));
dangling_limbs++; /*all operators have two limbs*/
}
else
{
rndint=random.Next(0,leafs.Length+1);
if(rndint==leafs.Length)
{
tree.Add((random.Next(0,10)));
}
else
{
tree.Add(leafs[rndint]);
}
dangling_limbs--;
}

}/*end for*/

dangling_limbs =0;;
//string temp=null;

}


i hope someone can help me out of it !!!!
Apr 28 '08 #1
0 828

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: James | last post by:
Just learning C#. What's the easiest way to assign numbers 1-10 randomly to an array? Basically I just want to take the numbers 1-10 and arrange them randomly in slots 0-9 of an array. Thanks
6
by: Fred Morrison | last post by:
Do you know of a way to load a hash table with random key/value pairs (e.g., 2/"Two",1/"One",3/"Three") and then iterate through the entries in "sorted" (key sequence) order...
9
by: Alan Isaac | last post by:
I need access to 2*n random choices for two types subject to a constraint that in the end I have drawn n of each. I first tried:: def random_types(n,typelist=): types = typelist*n...
5
by: John | last post by:
How can I fill an array randomly so it contains a certian range of numbers (1 - 100 for example) ? My Goal is to generate a set of numbers in random order.
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.