Files
LuaCsForBarotraumaEP/Subsurface/Source/Utils/Rand.cs
Regalis 40714c1102 - converting NetworkEvent sending time to local time before doing any comparisons
- using mersenne twister for random number generation due to differences in Mono and .NET implementations of the Random library
- password prompt for password-protected private servers
- fixed deconstructor, fabricator and railgun connection panels closing immediately after opening
- fixed editor saving newly created subs to the root folder instead of the Submarines folder
- keeping items in the same inventory slots between clients instead of just syncing which items are in the inventory
- fixed crashing when swapping items between different limbslots
2016-03-03 21:11:54 +02:00

46 lines
1.4 KiB
C#

using Lidgren.Network;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Barotrauma
{
static class Rand
{
private static Random localRandom = new Random();
private static Random syncedRandom = new MTRandom();
public static void SetSyncedSeed(int seed)
{
syncedRandom = new MTRandom(seed);
}
public static float Range(float minimum, float maximum, bool local = true)
{
return (float)(local ? localRandom : syncedRandom).NextDouble() * (maximum - minimum) + minimum;
}
public static int Range(int minimum, int maximum, bool local = true)
{
return (local ? localRandom : syncedRandom).Next(maximum - minimum) + minimum;
}
public static int Int(int max = int.MaxValue, bool local = true)
{
return (local ? localRandom : syncedRandom).Next(max);
}
public static Vector2 Vector(float length = 1.0f, bool local = true)
{
Vector2 randomVector = new Vector2(Range(-1.0f, 1.0f, local), Range(-1.0f, 1.0f, local));
if (randomVector == Vector2.Zero) return new Vector2(0.0f, length);
return Vector2.Normalize(randomVector) * length;
}
}
}