1
0

remove random.c

This commit is contained in:
dtb 2023-11-25 10:44:23 -07:00
parent 8a79df5a32
commit c97425f1f4
19 changed files with 17 additions and 173 deletions

View File

@ -44,6 +44,7 @@
*
*/
#include "random.h"
#include "rogue.h"
static int damage_for_strength(void);

View File

@ -50,6 +50,7 @@
#include <sys/types.h> /* <pwd.h> */
#include <pwd.h> /* getpwuid(3) */
#include "random.h"
#include "rogue.h"
static void do_args(int, char **);
@ -77,7 +78,6 @@ gid_t gid, egid;
int
init(int argc, char *argv[])
{
int seed;
int fd;
gid = getgid();
@ -89,7 +89,6 @@ init(int argc, char *argv[])
exit(1);
close(fd);
seed = 0;
{
char *ps;
struct passwd *p;
@ -130,8 +129,6 @@ init(int argc, char *argv[])
if (score_only) {
put_scores(NULL, 0);
}
seed = md_gseed();
(void)srrandom(seed);
if (rest_file) {
restore(rest_file);
return(1);

View File

@ -45,6 +45,7 @@
*/
#include <stdarg.h>
#include "random.h"
#include "rogue.h"
boolean is_wood[WANDS];

View File

@ -44,6 +44,7 @@
*
*/
#include "random.h"
#include "rogue.h"
#define SWAP(x,y) (t = (x), (x) = (y), (y) = t)

View File

@ -309,33 +309,6 @@ md_malloc(size_t n)
return(t);
}
/* md_gseed() (Get Seed)
*
* This function returns a seed for the random number generator (RNG). This
* seed causes the RNG to begin generating numbers at some point in its
* sequence. Without a random seed, the RNG will generate the same set
* of numbers, and every game will start out exactly the same way. A good
* number to use is the process id, given by getpid() on most UNIX systems.
*
* You need to find some single random integer, such as:
* process id.
* current time (minutes + seconds) returned from md_gct(), if implemented.
*
* It will not help to return "get_rand()" or "rand()" or the return value of
* any pseudo-RNG. If you don't have a random number, you can just return 1,
* but this means your games will ALWAYS start the same way, and will play
* exactly the same way given the same input.
*/
int
md_gseed(void)
{
time_t seconds;
time(&seconds);
return((int)seconds);
}
/* md_exit():
*
* This function causes the program to discontinue execution and exit.

View File

@ -12,7 +12,6 @@ boolean md_df(const char *fname);
void md_sleep(int nsecs);
char *md_getenv(const char *name);
void *md_malloc(size_t n);
int md_gseed(void);
void md_exit(int status);
void md_lock(boolean l);
void md_shell(const char *shell);

View File

@ -44,6 +44,7 @@
*
*/
#include "random.h"
#include "rogue.h"
object level_monsters;

View File

@ -44,6 +44,7 @@
*
*/
#include "random.h"
#include "rogue.h"
short m_moves = 0;

View File

@ -44,6 +44,7 @@
*
*/
#include "random.h"
#include "rogue.h"
object level_objects;

View File

@ -1,137 +0,0 @@
/* $NetBSD: random.c,v 1.8 2009/08/12 08:44:45 dholland Exp $ */
/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Timothy C. Stoehr.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "rogue.h"
/*
* random.c
*
* This source herein may be modified and/or distributed by anybody who
* so desires, with the following restrictions:
* 1.) No portion of this notice shall be removed.
* 2.) Credit shall not be taken for the creation of this source.
* 3.) This code is not to be traded, sold, or used for personal
* gain or profit.
*
*/
static long rntb[32] = {
3, 0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342,
0xde3b81e0, 0xdf0a6fb5, 0xf103bc02, 0x48f340fb, 0x7449e56b,
0xbeb1dbb0, 0xab5c5918, 0x946554fd, 0x8c2e680f, 0xeb3d799f,
0xb11ee0b7, 0x2d436b86, 0xda672e2a, 0x1588ca88, 0xe369735d,
0x904f35f7, 0xd7158fd6, 0x6fa6f051, 0x616e6b96, 0xac94efdc,
0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b, 0xf5ad9d0e,
0x8999220b, 0x27fb47b9
};
static long *fptr = &rntb[4];
static long *rptr = &rntb[1];
static long *state = &rntb[1];
static int rand_type = 3;
static int rand_deg = 31;
static int rand_sep = 3;
static long *end_ptr = &rntb[32];
static long rrandom(void);
void
srrandom(int x)
{
int i;
state[0] = x;
if (rand_type != 0) {
for (i = 1; i < rand_deg; i++) {
state[i] = 1103515245 * state[i - 1] + 12345;
}
fptr = &state[rand_sep];
rptr = &state[0];
for (i = 0; i < 10 * rand_deg; i++) {
(void)rrandom();
}
}
}
static long
rrandom(void)
{
long i;
if (rand_type == 0) {
i = state[0] = (state[0]*1103515245 + 12345) & 0x7fffffff;
} else {
*fptr += *rptr;
i = (*fptr >> 1) & 0x7fffffff;
if (++fptr >= end_ptr) {
fptr = state;
++rptr;
} else {
if (++rptr >= end_ptr) {
rptr = state;
}
}
}
return(i);
}
int
get_rand(int x, int y)
{
int r, t;
long lr;
if (x > y) {
t = y;
y = x;
x = t;
}
lr = rrandom();
lr &= 0x00003fffL;
r = (int)lr;
r = (r % ((y - x) + 1)) + x;
return(r);
}
int
rand_percent(int percentage)
{
return(get_rand(1, 100) <= percentage);
}
int
coin_toss(void)
{
return(((rrandom() & 01) ? 1 : 0));
}

3
rogue/random.h Normal file
View File

@ -0,0 +1,3 @@
#define get_rand(x, y) (((rand() % ((y) - (x))) + 1) + (x)) /* 0 index */
#define rand_percent(odds) ((rand() % 99 + 1) <= (odds))
#define coin_toss (rand() & 1)

View File

@ -44,6 +44,7 @@
*
*/
#include "random.h"
#include "rogue.h"
static const char left_or_right[] = "left or right hand?";

View File

@ -503,7 +503,6 @@ int get_hit_chance(const object *);
int get_input_line(const char *, const char *, char *, size_t, const char *, boolean, boolean);
char get_mask_char(unsigned short);
int get_number(const char *);
int get_rand(int, int);
short get_room_number(int, int);
void get_wand_and_ring_materials(void);
int get_weapon_damage(const object *);
@ -543,7 +542,6 @@ void md_exit(int) __dead;
void md_gct(struct rogue_time *);
int md_get_file_id(const char *);
void md_gfmt(const char *, struct rogue_time *);
int md_gseed(void);
void md_heed_signals(void);
void md_ignore_signals(void);
int md_link_count(const char *);
@ -587,7 +585,6 @@ void quaff(void);
void quit(boolean);
int r_index(const char *, int, boolean);
void rand_around(short, short *, short *);
int rand_percent(int);
void read_scroll(void);
boolean reg_move(void);
void relight(void);
@ -613,7 +610,6 @@ void show_traps(void);
void single_inv(short);
void sound_bell(void);
void special_hit(object *);
void srrandom(int);
void start_window(void);
void stop_window(void);
void take_a_nap(void);

View File

@ -44,6 +44,7 @@
*
*/
#include "random.h"
#include "rogue.h"
room rooms[MAXROOMS];

View File

@ -44,6 +44,7 @@
*
*/
#include "random.h"
#include "rogue.h"
static void disappear(object *);

View File

@ -44,6 +44,7 @@
*
*/
#include "random.h"
#include "rogue.h"
static void flop_weapon(object *, short, short);

View File

@ -44,6 +44,7 @@
*
*/
#include "random.h"
#include "rogue.h"
trap traps[MAX_TRAPS];

View File

@ -44,6 +44,7 @@
*
*/
#include "random.h"
#include "rogue.h"
short halluc = 0;

View File

@ -44,6 +44,7 @@
*
*/
#include "random.h"
#include "rogue.h"
static object *get_zapped_monster(short, short *, short *);