E
Ethan Strauss
Hi,
There have been quite a few discussions of Random not giving random
numbers and how to fix that by feeding in a new seed each time, waiting
enough time, or calling the Next() method of the Random object. I have
another wrinkle....
I have created a static Random DNA sequence generator (it is really just
a random number generator with a little chrome). Since it is static, I can't
use the .Next method for multiple calls to the object (or if I can, can you
please let me know how?). Right now, I am have a sister method which allows
the user to pass in a seed, so I can generate THAT seed with a random number
on which I call Next() each time. After discussion from this group, I though
I might add a Thread.Sleep() to the unseeded version and have it wait a tick
each time before running, but a trick turns out not to be long enough! I
found that I have to wait ~80000 ticks before I get a new random number! If
anyone knows of a better way to get this static method to be more truely
random without waiting that long, I would be interested.
Here is the method
public static string RandomSequence (int length)
{
Random Number = new Random();
StringBuilder RandomSequence = new StringBuilder();
int ThisBase; "
for (int Base = 1; Base <= length; Base++)
{
ThisBase = Number.Next(4);
switch (ThisBase)
{
case 0:
RandomSequence.Append("A");
break;
case 1:
RandomSequence.Append("G");
break;
case 2:
RandomSequence.Append("T");
break;
case 3:
RandomSequence.Append("C");
break;
default:
break;
}
}
return RandomSequence.ToString();
}
and here is what I did to determine how many ticks it takes to get a new
number
private void Page_Load(object sender, System.EventArgs e)
{
int NumberNumber = 20;
TimeSpan ATick = new TimeSpan(10000L);
for (int Counter = 0; Counter < NumberNumber;
Counter++)//This returns the same sequence each time
{
RandomNumberLabel.Text += "<br>" +
BiologyTools.NucleicAcidSequence.RandomSequence(10, 20);
}
RandomNumberLabel.Text += "<p>";
for (int Counter = 0; Counter < NumberNumber;
Counter++)//This changes every 8 passes
{
System.Threading.Thread.Sleep(ATick);
RandomNumberLabel.Text += "<br>" +
BiologyTools.NucleicAcidSequence.RandomSequence(10, 20);
}
}
Ethan
There have been quite a few discussions of Random not giving random
numbers and how to fix that by feeding in a new seed each time, waiting
enough time, or calling the Next() method of the Random object. I have
another wrinkle....
I have created a static Random DNA sequence generator (it is really just
a random number generator with a little chrome). Since it is static, I can't
use the .Next method for multiple calls to the object (or if I can, can you
please let me know how?). Right now, I am have a sister method which allows
the user to pass in a seed, so I can generate THAT seed with a random number
on which I call Next() each time. After discussion from this group, I though
I might add a Thread.Sleep() to the unseeded version and have it wait a tick
each time before running, but a trick turns out not to be long enough! I
found that I have to wait ~80000 ticks before I get a new random number! If
anyone knows of a better way to get this static method to be more truely
random without waiting that long, I would be interested.
Here is the method
public static string RandomSequence (int length)
{
Random Number = new Random();
StringBuilder RandomSequence = new StringBuilder();
int ThisBase; "
for (int Base = 1; Base <= length; Base++)
{
ThisBase = Number.Next(4);
switch (ThisBase)
{
case 0:
RandomSequence.Append("A");
break;
case 1:
RandomSequence.Append("G");
break;
case 2:
RandomSequence.Append("T");
break;
case 3:
RandomSequence.Append("C");
break;
default:
break;
}
}
return RandomSequence.ToString();
}
and here is what I did to determine how many ticks it takes to get a new
number
private void Page_Load(object sender, System.EventArgs e)
{
int NumberNumber = 20;
TimeSpan ATick = new TimeSpan(10000L);
for (int Counter = 0; Counter < NumberNumber;
Counter++)//This returns the same sequence each time
{
RandomNumberLabel.Text += "<br>" +
BiologyTools.NucleicAcidSequence.RandomSequence(10, 20);
}
RandomNumberLabel.Text += "<p>";
for (int Counter = 0; Counter < NumberNumber;
Counter++)//This changes every 8 passes
{
System.Threading.Thread.Sleep(ATick);
RandomNumberLabel.Text += "<br>" +
BiologyTools.NucleicAcidSequence.RandomSequence(10, 20);
}
}
Ethan