Dwarrowdelf.MWCRandom.Next C# (CSharp) Method

Next() public method

Get random Int32 [0, Int32.MaxValue)
public Next ( ) : int
return int
        public int Next()
        {
            uint u = NextUint();
            return (int)(u * ((double)(Int32.MaxValue - 1) / UInt32.MaxValue));
        }

Same methods

MWCRandom::Next ( int exclusiveMax ) : int

Usage Example

Example #1
0
        public static void CreateSlopes(TerrainData data, int baseSeed)
        {
            var plane = data.Size.Plane;

            plane.Range().AsParallel().ForAll(p =>
            {
                int z = data.GetHeight(p);

                int count = 0;
                Direction dir = Direction.None;

                var r = new MWCRandom(p, baseSeed);

                int offset = r.Next(8);

                // Count the tiles around this tile which are higher. Create slope to a random direction, but skip
                // the slope if all 8 tiles are higher.
                // Count to 10. If 3 successive slopes, create one in the middle
                int successive = 0;
                for (int i = 0; i < 10; ++i)
                {
                    var d = DirectionExtensions.PlanarDirections[(i + offset) % 8];

                    var t = p + d;

                    if (plane.Contains(t) && data.GetHeight(t) > z)
                    {
                        if (i < 8)
                            count++;
                        successive++;

                        if (successive == 3)
                        {
                            dir = DirectionExtensions.PlanarDirections[((i - 1) + offset) % 8];
                        }
                        else if (dir == Direction.None)
                        {
                            dir = d;
                        }
                    }
                    else
                    {
                        successive = 0;
                    }
                }

                if (count > 0 && count < 8)
                {
                    var p3d = new IntPoint3(p, z);

                    var td = data.GetTileData(p3d);
                    td.TerrainID = dir.ToSlope();
                    data.SetTileData(p3d, td);
                }
            });
        }
All Usage Examples Of Dwarrowdelf.MWCRandom::Next