K
Ken Fine
Hi there,
I have written a simple function that attempts to set the angle of objects
so as to place them in aesthetically appealing ways. The code follows; there
is some stupidness in it (e.g. a test for meaningless <=180 as a boolean
test). The function is designed to return values that will avoid positioning
things a) upside down and b) at "too steep" an angle.
I would now like to know how I could write my function so that the machine
would pick semi-random numbers, but so that those numbers would be biased
toward a prespecified value. Ideally it could be parameterized such that you
could choose (for lack of a better term) a "gravity" setting. In other
words, there would be paramaterized "knob" that indicated how willing you
were to let the numbers deviate from your prespecified center value. Low
"gravity" would let the numbers float all over the place, with only slight
bias. High gravity would bias the selection very strongly toward the center.
This would be useful in all sorts of ways.
I should have paid more attention in math class. Can someone offer a
suggestion? Code follows.
private int GetRandomAngle()
{
Random rand = this.Session["MyRandom"] as Random;
int rand1= rand.Next(0, 360);
if (rand1 >= 180)
{
return(rand.Next(270,360));
}
if (rand1 <=180)
{
return(rand.Next(10, 70));
}
return (rand.Next(280, 340));
}
I have written a simple function that attempts to set the angle of objects
so as to place them in aesthetically appealing ways. The code follows; there
is some stupidness in it (e.g. a test for meaningless <=180 as a boolean
test). The function is designed to return values that will avoid positioning
things a) upside down and b) at "too steep" an angle.
I would now like to know how I could write my function so that the machine
would pick semi-random numbers, but so that those numbers would be biased
toward a prespecified value. Ideally it could be parameterized such that you
could choose (for lack of a better term) a "gravity" setting. In other
words, there would be paramaterized "knob" that indicated how willing you
were to let the numbers deviate from your prespecified center value. Low
"gravity" would let the numbers float all over the place, with only slight
bias. High gravity would bias the selection very strongly toward the center.
This would be useful in all sorts of ways.
I should have paid more attention in math class. Can someone offer a
suggestion? Code follows.
private int GetRandomAngle()
{
Random rand = this.Session["MyRandom"] as Random;
int rand1= rand.Next(0, 360);
if (rand1 >= 180)
{
return(rand.Next(270,360));
}
if (rand1 <=180)
{
return(rand.Next(10, 70));
}
return (rand.Next(280, 340));
}