1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Split libmaxsi random.o into multiple files.

This commit is contained in:
Jonas 'Sortie' Termansen 2012-09-28 20:33:04 +02:00
parent 4556036e08
commit 0e7518915e
2 changed files with 31 additions and 29 deletions

View file

@ -165,7 +165,7 @@ open.o \
pipe.o \
print.o \
putc.o \
random.o \
rand.o \
readdirents.o \
read.o \
rmdir.o \

View file

@ -1,6 +1,6 @@
/*******************************************************************************
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012.
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
This file is part of LibMaxsi.
@ -17,36 +17,38 @@
You should have received a copy of the GNU Lesser General Public License
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
random.cpp
Provides access to random numbers using various algorithms.
rand.cpp
Returns a random value.
*******************************************************************************/
namespace Maxsi
{
namespace Random
{
#include <stdlib.h>
#if 1
unsigned int m_w = 1337;
unsigned int m_z = 37;
unsigned int RandomUnsignedInt()
{
m_z = 36969 * (m_z & 65535) + (m_z >> 16);
m_w = 18000 * (m_w & 65535) + (m_w >> 16);
return (m_z << 16) + m_w; /* 32-bit result */
}
extern "C" int rand()
{
return RandomUnsignedInt() % 32768;
}
#else
unsigned random_seed = 1337;
extern "C" int rand()
{
random_seed = random_seed + 37 * 1103515245 + 12345;
return random_seed >> 16;
}
#endif
}
static unsigned int m_w = 1337;
static unsigned int m_z = 37;
static unsigned int RandomUnsignedInt()
{
m_z = 36969 * (m_z & 65535) + (m_z >> 16);
m_w = 18000 * (m_w & 65535) + (m_w >> 16);
return (m_z << 16) + m_w; /* 32-bit result */
}
extern "C" int rand()
{
return RandomUnsignedInt() % 32768;
}
#else
static unsigned random_seed = 1337;
extern "C" int rand()
{
random_seed = random_seed + 37 * 1103515245 + 12345;
return random_seed >> 16;
}
#endif