1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:17:36 +00:00

IPv4: Add simple pseudorandom ephemeral port allocators for TCP and UDP.

This commit is contained in:
Andreas Kling 2019-03-18 04:03:44 +01:00
parent 77a782a67e
commit c24d4b07db
8 changed files with 54 additions and 20 deletions

View file

@ -16,12 +16,17 @@ RandomDevice::~RandomDevice()
static unsigned long next = 1;
#define MY_RAND_MAX 32767
static int myrand()
int RandomDevice::random_value()
{
next = next * 1103515245 + 12345;
return((unsigned)(next/((MY_RAND_MAX + 1) * 2)) % (MY_RAND_MAX + 1));
}
float RandomDevice::random_percentage()
{
return (float)random_value() / (float)MY_RAND_MAX;
}
#if 0
static void mysrand(unsigned seed)
{
@ -39,7 +44,7 @@ ssize_t RandomDevice::read(Process&, byte* buffer, ssize_t size)
const int range = 'z' - 'a';
ssize_t nread = min(size, GoodBufferSize);
for (ssize_t i = 0; i < nread; ++i) {
dword r = myrand() % range;
dword r = random_value() % range;
buffer[i] = (byte)('a' + r);
}
return nread;