本文整理汇总了C#中System.Random.NextDouble方法的典型用法代码示例。如果您正苦于以下问题:C# Random.NextDouble方法的具体用法?C# Random.NextDouble怎么用?C# Random.NextDouble使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Random
的用法示例。
在下文中一共展示了Random.NextDouble方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Pigeon
public Pigeon(ContentManager con)
{
boundingBox = new Vector3(6, 3, 6);
distance = 0;
rand = new Random();
dx = (0.5-rand.NextDouble())*0.8 + 0.2;
dy = rand.NextDouble()*1.5 + 0.7;
dz = 0.8;
x = 5.8;
y = -2;
z = 83.5;
sx = 5.8;
sy = -2;
sz = 83.5;
this.world = Matrix.CreateTranslation(new Vector3((float)x, (float)y, (float)z));
model = con.Load<Model>(@"models/pigeon");
isDone = false;
}
示例2: SimpleNoise2d
/// <summary>
/// Setup constructor
/// </summary>
private SimpleNoise2d( Random rnd )
{
m_Perm = new int[ 64 ];
for ( int permIndex = 0; permIndex < m_Perm.Length; ++permIndex )
{
m_Perm[ permIndex ] = permIndex;
}
for ( int permIndex = 0; permIndex < m_Perm.Length; ++permIndex )
{
int swapIndex0 = rnd.Next( m_Perm.Length );
int swapIndex1 = rnd.Next( m_Perm.Length );
int tmpValue = m_Perm[ swapIndex0 ];
m_Perm[ swapIndex0 ] = m_Perm[ swapIndex1 ];
m_Perm[ swapIndex1 ] = tmpValue;
}
m_GradX = new float[ 64 ];
m_GradY = new float[ 64 ];
for ( int gradIndex = 0; gradIndex < m_GradX.Length; ++gradIndex )
{
float m;
// Generate a random, non-zero length vector within the unit circle
do
{
m_GradX[ gradIndex ] = ( ( float )rnd.NextDouble( ) * 2.0f ) - 1.0f;
m_GradY[ gradIndex ] = ( ( float )rnd.NextDouble( ) * 2.0f ) - 1.0f;
m = m_GradX[ gradIndex ] * m_GradX[ gradIndex ] + m_GradY[ gradIndex ] * m_GradY[ gradIndex ];
} while ( ( m == 0.0f ) && ( m > 1.0f ) );
// Normalize the vector
m = 1.0f / ( float )Math.Sqrt( m );
m_GradX[ gradIndex ] *= m;
m_GradY[ gradIndex ] *= m;
}
}
示例3: UpdateParticlesData
private void UpdateParticlesData(ParticleEmitterComponent smokeParticleEmitterComponent)
{
bool isUptoDate = true;
if (ParticleData == null || ParticleData.Length != Count)
{
ParticleData = new ScriptParticleSmoke.ParticleData[Count];
isUptoDate = false;
}
if (isUptoDate)
return;
var description = Description;
var random = new Random();
var particlesBuffer = (ScriptParticleSmoke.ParticleData[])ParticleData;
for (int i = 0; i < particlesBuffer.Length; i++)
{
particlesBuffer[i] = new ScriptParticleSmoke.ParticleData
{
Position = description.Position,
Velocity = (Half3)(description.Velocity + Vector3.Modulate(new Vector3((float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble())), description.Scatter)),
Size = (Half)description.InitialSize,
Time = (float)random.NextDouble() * description.MaxTime,
Opacity = (Half)description.Opacity,
Factors = new Half4((Half)random.NextDouble(), (Half)0, (Half)description.Opacity, (Half)0),
TimeStep = (Half)10.0f,
};
particlesBuffer[i].Position += ((Vector3)particlesBuffer[i].Velocity) * particlesBuffer[i].Time * 100.0f / 1000.0f;
}
}
示例4: Page_Loaded
private void Page_Loaded(object sender, RoutedEventArgs e)
{
plotter.Visible = new DataRect(0, 0, 1, 1);
int count = (int)1e4;
Point[] pts = new Point[count];
Random rnd = new Random();
for (int i = 0; i < count; i++)
{
pts[i] = new Point(rnd.NextDouble(), rnd.NextDouble());
}
markerChart.AddPropertyBinding<Point>(Shape.ToolTipProperty, p =>
{
return String.Format("X: {0:F2} Y: {1:F2}", p.X, p.Y);
});
HSBPalette palette = new HSBPalette();
markerChart.AddPropertyBinding<Point>(Shape.FillProperty, p =>
{
double length = Math.Sqrt(p.X * p.X + p.Y * p.Y) / Math.Sqrt(2);
return new SolidColorBrush(palette.GetColor(length));
});
//markerChart.Filters.Add(new BoundsFilter());
//markerChart.Filters.Add(new ParallelUnitingPointGroupFilter());
//markerChart.Filters.Add(new ParallelClusteringFilter { MarkerSize = 8 });
markerChart.Filters.Add(new UnitingPointGroupFilter { MarkerSize = 6 });
//markerChart.GetDataAsyncronously = true;
//markerChart.ShowMarkersConsequently = false;
markerChart.ItemsSource = pts;
}
示例5: Start
public static void Start(Random rnd)
{
int length = 4096;
var masComplex1 = new Complex[length];
var masSimdComplex1 = new Vector2[length];
var masComplex2 = new Complex[length];
var masSimdComplex2 = new Vector2[length];
for (int i = 0; i < length; i++)
{
float v1 = (float) rnd.NextDouble()*1000;
float v2 = (float) rnd.NextDouble()*1000;
masComplex1[i] = new Complex(v1, v2);
masSimdComplex1[i] = new Vector2(v1,v2);
v1 = (float)rnd.NextDouble() * 1000;
v2 = (float)rnd.NextDouble() * 1000;
masComplex2[i] = new Complex(v1, v2);
masSimdComplex2[i] = new Vector2(v1, v2);
}
Extensions.TestTime(() =>
TestWithoutSimd(masComplex1, masComplex2),
"Время для complex ");
Extensions.TestTime(() =>
TestWithSimd(masSimdComplex1, masSimdComplex2),
"Время для complex(simd) ");
}
示例6: Generate
public Model3D Generate()
{
int count = 1000;
Vector3[] v = new Vector3[count];
Vector3[] r = new Vector3[count];
Random random = new Random();
Color[] color = new Color[count];
float[] m = new float[count];
for (int i = 0; i < count; i++)
{
v[i] = new Vector3(0,
0,
0);
/* r[i] = new Vector3((float)random.NextDouble() * 1,
(float)random.NextDouble() * 1,
(float)random.NextDouble() * 1);*/
r[i] = new Vector3((float)random.NextDouble() ,
(float)random.NextDouble() ,
(float)random.NextDouble() );
m[i] = random.Next(10, 100);
color[i] = Color.FromArgb(random.Next(100, 200), random.Next(100, 200), random.Next(100, 200));
}
Model3D model3D = new Model3D(r, v, m, color);
model3D.G = 0.1f;
return model3D;
}
示例7: Multipg
public void Multipg()
{
Random rnd = new Random();
Polygon[] pg = new Polygon[50];
GeoAPI.Geometries.IPolygon[] pgcheck = new GeoAPI.Geometries.IPolygon[50];
GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory();
for (int i = 0; i < 50; i++)
{
Coordinate center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
Coordinate[] coord = new Coordinate[36];
GeoAPI.Geometries.ICoordinate[] coordscheck = new GeoAPI.Geometries.ICoordinate[36];
for (int ii = 0; ii < 36; ii++)
{
coord[ii] = new Coordinate(center.X + Math.Cos((ii * 10) * Math.PI / 10), center.Y + (ii * 10) * Math.PI / 10);
double x = coord[ii].X;
double y = coord[ii].Y;
GisSharpBlog.NetTopologySuite.Geometries.Coordinate c = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y);
coordscheck[ii] = c;
}
coord[35] = new Coordinate(coord[0].X, coord[0].Y);
coordscheck[35] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y);
GeoAPI.Geometries.ILinearRing ring = gf.CreateLinearRing(coordscheck);
pgcheck[i] = gf.CreatePolygon(ring, null);
pg[i] = new Polygon(coord);
}
MultiPolygon mpg = new MultiPolygon(pg);
GeoAPI.Geometries.IMultiPolygon mpgcheck = gf.CreateMultiPolygon(pgcheck);
for (int ii = 0; ii < mpg.Coordinates.Count; ii++)
{
Assert.AreEqual(mpg.Coordinates[ii].X, mpgcheck.Coordinates[ii].X);
Assert.AreEqual(mpg.Coordinates[ii].Y, mpgcheck.Coordinates[ii].Y);
}
}
示例8: ElmansNetwork
public ElmansNetwork(int numberOfEntryNeurons,int numberOfHiddenNeurons, int numberOfExitNeurons, bool useTechnicalAnalysis)
{
realNumberOfEntryNeurons = numberOfEntryNeurons + 1;
if (useTechnicalAnalysis)
realNumberOfEntryNeurons += 2;
this.useTechnicalAnalysis = useTechnicalAnalysis;
entryValues = new double[realNumberOfEntryNeurons];
contextValues = new double[numberOfHiddenNeurons];
hiddenValues = new double[numberOfHiddenNeurons + 1];
exitValues = new double[numberOfExitNeurons];
errorValues = new double[numberOfExitNeurons];
this.numberOfExitNeurons = numberOfExitNeurons;
this.numberOfHiddenNeurons = numberOfHiddenNeurons;
this.numberOfEntryNeurons = numberOfEntryNeurons;
this.numberOfContextNeurons = numberOfHiddenNeurons;
Random rand = new Random();
entryHiddenWeights = new double[this.realNumberOfEntryNeurons, this.numberOfHiddenNeurons];
contextHiddenWeights = new double[this.numberOfContextNeurons, this.numberOfHiddenNeurons];
hiddenExitWeights = new double[this.numberOfHiddenNeurons + 1, this.numberOfExitNeurons];
entryValues[entryValues.Length - 1] = 1;
hiddenValues[hiddenValues.Length - 1] = 1;
for (int i = 0; i < realNumberOfEntryNeurons; i++)
for (int j = 0; j < numberOfHiddenNeurons; j++)
entryHiddenWeights[i, j] = rand.NextDouble();
for (int i = 0; i < numberOfContextNeurons; i++)
for (int j = 0; j < numberOfHiddenNeurons; j++)
contextHiddenWeights[i, j] = rand.NextDouble();
for (int i = 0; i < numberOfHiddenNeurons + 1; i++)
for (int j = 0; j < numberOfExitNeurons; j++)
hiddenExitWeights[i, j] = rand.NextDouble();
}
示例9: Generate
private static uint[] Generate(int width, int height, double tileSize, double cameraZ, double cameraAngleOfView, uint iteration)
{
var random = new Random();
var result = new uint[width * height];
var stopwatch = new Stopwatch();
stopwatch.Start();
for (uint i = 1; i <= iteration; ++i)
{
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
var intersection = GetIntersection(cameraZ, cameraAngleOfView, width, height, x + random.NextDouble(), y + random.NextDouble());
result[width * y + x] += GetColor(tileSize, intersection.Item1, intersection.Item2);
}
}
Console.WriteLine($"Iteration {i} / {iteration}, Remaining time: {TimeSpan.FromMilliseconds(stopwatch.ElapsedMilliseconds * ((iteration - i) / (double)i))}");
}
return result;
}
示例10: TargetTrackingImpl
public TargetTrackingImpl(double sigma_f, double dT, string screenSize, string cameraType)
{
this.screenSize = screenSize;
this.sigma_f = sigma_f;
this.cameraType = cameraType;
SPOI.Zero();
Sx2.Zero();
for (int i = 0; i < 7; i++)
{
if (i < 3)
SPOI[i, i] = 0.5;
else
SPOI[i, i] = 0.001;
}
for (int i = 0; i < 9; i++)
{
if (i < 6)
Sx2[i, i] = 0.1;
else
Sx2[i, i] = 0.01;
}
Random r = new Random();
SSCR[2, 2] = 0.01; // laser covariance
scr_noise[0, 0] = r.NextDouble() * 10; scr_noise[1, 0] = r.NextDouble() * 10;
algorithm = new TargetTrackingAlgorithm(dT);
}
示例11: btnMakePoints_Click
private void btnMakePoints_Click(object sender, RoutedEventArgs e)
{
drawingCanvas.Children.Clear();
var sizeX = drawingCanvas.ActualWidth;
var sizeY = drawingCanvas.ActualHeight;
vertices = new List<Vertex>();
var r = new Random();
/****** Random Vertices ******/
for (var i = 0; i < NumberOfVertices; i++)
{
var vi = new Vertex(sizeX * r.NextDouble(), sizeY * r.NextDouble());
vertices.Add(vi);
}
ShowVertices();
var now = DateTime.Now;
voronoiMesh = VoronoiMesh.Create<Vertex, Cell>(vertices);
var interval = DateTime.Now - now;
txtBlkTimer.Text = string.Format("{0:0.000}s ({1} faces)", interval.TotalSeconds, voronoiMesh.Vertices.Count());
btnFindDelaunay.IsEnabled = true;
btnFindVoronoi.IsEnabled = true;
}
示例12: AsyncPipelineWaitTest
public void AsyncPipelineWaitTest()
{
Random rand = new Random(222);
int started = 0;
int finished1 = 0;
int finished2 = 0;
int numActions = 1000;
Action action1 = (() =>
{
lock (this) started++;
Thread.Sleep((int)(rand.NextDouble() * 100));
lock (this) finished1++;
});
Action action2 = (() =>
{
Thread.Sleep((int)(rand.NextDouble() * 100));
lock (this) finished2++;
});
var pipeline = new AsyncPipeline(10);
for (int i = 0; i < numActions; i++)
{
var async1 = Task.Run(action1);
pipeline.Add(async1);
var async2 = async1.ContinueWith(_ => action2());
pipeline.Add(async2);
}
pipeline.Wait();
Assert.AreEqual(numActions, started);
Assert.AreEqual(numActions, finished1);
Assert.AreEqual(numActions, finished2);
}
示例13: OnLoadScene
public override Scene OnLoadScene()
{
this.mEngine.RegisterUpdateHandler(new FPSLogger());
Scene scene = new Scene(1);
scene.Background = new ColorBackground(0.09804f, 0.6274f, 0.8784f);
Random random = new Random(RANDOM_SEED);
for (int i = 0; i < LINE_COUNT; i++)
{
float x1 = (float)(random.NextDouble() * CAMERA_WIDTH);
float x2 = (float)(random.NextDouble() * CAMERA_WIDTH);
float y1 = (float)(random.NextDouble() * CAMERA_HEIGHT);
float y2 = (float)(random.NextDouble() * CAMERA_HEIGHT);
float lineWidth = (float)(random.NextDouble() * 5);
Line line = new Line(x1, y1, x2, y2, lineWidth);
line.SetColor((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble());
scene.getLastChild().attachChild(line);
}
return scene;
}
示例14: Particle
public Particle(Texture2D texture, Vector2 position, Random random)
{
int whichColor = random.Next(3);
Texture = texture;
Position = position;
Velocity = new Vector2(0,0);
Angle = 0;
AngularVelocity = 0.05f * (float)(random.NextDouble() * 2 - 1);
Size = (float)random.NextDouble() / 2;
TTL = 1000;
switch (whichColor)
{
case 0:
Color = new Color(20, 20, 20);
break;
case 1:
Color = new Color(40, 40, 40);
break;
case 2:
Color = new Color(60, 60, 60);
break;
default:
Color = Color.Black;
break;
}
sizeOverride = true;
Randomness = new Vector2((float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble() * 2 - 1));
}
示例15: RangeColorAxis
private static PlotModel RangeColorAxis(AxisPosition position)
{
int n = 1000;
var model = new PlotModel
{
Title = string.Format("ScatterSeries and RangeColorAxis (n={0})", n),
Background = OxyColors.LightGray
};
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
var rca = new RangeColorAxis { Position = position, Maximum = 2, Minimum = -2 };
rca.AddRange(0, 0.5, OxyColors.Blue);
rca.AddRange(-0.2, -0.1, OxyColors.Red);
model.Axes.Add(rca);
var s1 = new ScatterSeries { MarkerType = MarkerType.Square, MarkerSize = 6, };
var random = new Random(13);
for (int i = 0; i < n; i++)
{
double x = (random.NextDouble() * 2.2) - 1.1;
s1.Points.Add(new ScatterPoint(x, random.NextDouble()) { Value = x });
}
model.Series.Add(s1);
return model;
}