本文整理匯總了C#中System.Random.NextInteger方法的典型用法代碼示例。如果您正苦於以下問題:C# Random.NextInteger方法的具體用法?C# Random.NextInteger怎麽用?C# Random.NextInteger使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Random
的用法示例。
在下文中一共展示了Random.NextInteger方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: RandomizedMassSceneUpdate2
public void RandomizedMassSceneUpdate2()
{
const int NumberOfSceneNodes = 10;
const int NumberOfSteps = 10000;
const float WorldSize = 1000;
var random = new Random(123457);
var scene = new Scene();
scene.EnableMultithreading = false;
var nodes = new TestSceneNode[NumberOfSceneNodes];
// Create random nodes.
for (int i = 0; i < NumberOfSceneNodes; i++)
{
var node = new TestSceneNode();
nodes[i] = node;
var position = random.NextVector3F(0, WorldSize);
var orientation = random.NextQuaternionF();
node.PoseLocal = new Pose(position, orientation);
float p = random.NextFloat(0, 100);
if (p < 0.1f)
node.Shape = Shape.Empty;
else if (p < 0.2f)
node.Shape = Shape.Infinite;
else if (p < 0.6f)
node.Shape = new BoxShape(random.NextVector3F(0, WorldSize));
else
node.Shape = new SphereShape(random.NextFloat(0, WorldSize));
}
var projection = new PerspectiveProjection();
projection.SetFieldOfView(0.8f, 1, WorldSize / 10000, WorldSize);
var camera = new Camera(projection);
var cameraNode = new CameraNode(camera);
for (int updateIndex = 0; updateIndex < NumberOfSteps; updateIndex++)
{
int actionsPerFrame = random.NextInteger(0, 100);
for (int i = 0; i < actionsPerFrame; i++)
{
var node = nodes[random.Next(0, NumberOfSceneNodes)];
const int numberOfActions = 100;
int action = random.Next(0, numberOfActions);
//scene.Validate();
if (action == 0)
{
// Add
if (node.Parent == null)
{
scene.Children.Add(node);
//scene.Validate();
}
}
else if (action == 1)
{
// Remove
if (node.Parent != null)
{
node.Parent.Children.Remove(node);
//scene.Validate();
}
}
else if (action == 2)
{
// Move
var pose = node.PoseWorld;
pose.Position = random.NextVector3F(0, WorldSize);
node.PoseWorld = pose;
//scene.Validate();
}
else if (action == 3)
{
// Very small Move
var pose = node.PoseWorld;
const float maxDistance = WorldSize / 10000;
pose.Position += random.NextVector3F(-maxDistance, maxDistance);
node.PoseWorld = pose;
//scene.Validate();
}
else if (action == 4)
{
// Small Move
var pose = node.PoseWorld;
const float maxDistance = WorldSize / 100;
pose.Position += random.NextVector3F(-maxDistance, maxDistance);
node.PoseWorld = pose;
//scene.Validate();
}
else if (action == 5)
{
// Scale
node.ScaleLocal = random.NextVector3F(0.0f, 10f);
//scene.Validate();
}
//.........這裏部分代碼省略.........