Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce loadable pseudo-random number generators. #200

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ jobs:
- { os: ubuntu-latest, name: 'Heap Test', opt: '--enable-debugheap --enable-verifyheap --enable-werror' }
- { os: ubuntu-latest, name: 'Thin Build', opt: '--enable-thin --enable-werror' }
- { os: ubuntu-latest, name: 'Dev Mode', opt: '--enable-devmode' }
- { os: ubuntu-latest, name: 'Rng Libraries', opt: '--enable-rnglibs' }
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
6 changes: 4 additions & 2 deletions Makedefs.in
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@ datarootdir=@datarootdir@
docdir=@docdir@
mandir=@mandir@
htmldir=@htmldir@

SQLITE=@SQLITE@

# Used by plugins
SQLITE=@SQLITE@
GSLRNG=@GSLRNG@
RNGLIBS=@RNGLIBS@

# configuration parameters

Expand Down
86 changes: 85 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,9 @@ XL
GRAPHICS
XLIBS
CXXCPP
GSLRNG
SQLITE
RNGLIBS
LIBOBJS
HTMLDOC
UDOC
Expand Down Expand Up @@ -763,6 +765,7 @@ enable_iconcurrency
enable_ovld
enable_udbtools
enable_progs
enable_rnglibs
enable_verbosebuild
enable_doc
enable_htmldoc
Expand Down Expand Up @@ -1444,6 +1447,7 @@ Optional Features:
--enable-ovld Enable operator overloading
--enable-udbtools Enable Unicon debugger tools
--enable-progs Enable Unicon programs
--enable-rnglibs Enable loadable random number generators
--enable-verbosebuild Show full CC build lines with all compiler arguments
--enable-doc Add makefile rule to build documentation
--enable-htmldoc Add makefile rule to html documentation
Expand Down Expand Up @@ -3233,6 +3237,13 @@ else
verifyheap=no
fi

# Check whether --enable-rnglibs was given.
if test "${enable_rnglibs+set}" = set; then :
enableval=$enable_rnglibs; rnglibs=yes
else
rnglibs=no
fi

# Check whether --enable-devmode was given.
if test "${enable_devmode+set}" = set; then :
enableval=$enable_devmode; devmode=$enableval
Expand Down Expand Up @@ -4781,6 +4792,14 @@ $as_echo "#define VerifyHeap 1" >>confdefs.h
verifyheapreport="VerifyHeap"
fi

if test x"$rnglibs" = x"yes" ; then

$as_echo "#define RngLibrary 1" >>confdefs.h

RNGLIBS=1

fi

if test x"$udbtools" = x"yes" ; then
UDBTOOLS=udbtools
fi
Expand Down Expand Up @@ -7657,7 +7676,7 @@ _ACEOF
fi


# we don't need sqlite to be added to $LIBS, not yet at least
# Check for libs for plugin use, don't add to these to $LIBS
saved_libs="$LIBS"
for ac_header in sqlite3.h
do :
Expand Down Expand Up @@ -7716,6 +7735,63 @@ _ACEOF

fi

for ac_header in gsl/gsl_rng.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "gsl/gsl_rng.h" "ac_cv_header_gsl_gsl_rng_h" "$ac_includes_default"
if test "x$ac_cv_header_gsl_gsl_rng_h" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_GSL_GSL_RNG_H 1
_ACEOF

fi

done

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for gsl_rng_set in -lgsl" >&5
$as_echo_n "checking for gsl_rng_set in -lgsl... " >&6; }
if ${ac_cv_lib_gsl_gsl_rng_set+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lgsl $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char gsl_rng_set ();
int
main ()
{
return gsl_rng_set ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_gsl_gsl_rng_set=yes
else
ac_cv_lib_gsl_gsl_rng_set=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_gsl_gsl_rng_set" >&5
$as_echo "$ac_cv_lib_gsl_gsl_rng_set" >&6; }
if test "x$ac_cv_lib_gsl_gsl_rng_set" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_LIBGSL 1
_ACEOF

LIBS="-lgsl $LIBS"

fi


LIBS="$saved_libs"

if test "x$ac_cv_header_sqlite3_h" = "xyes" -a "x$ac_cv_lib_sqlite3_sqlite3_config" = "xyes"; then
Expand All @@ -7724,6 +7800,14 @@ else
SQLITE=""
fi

if test "x$ac_cv_header_gsl_gsl_rng_h" = "xyes" -a "x$ac_cv_lib_gsl_gsl_rng_set" = "xyes"; then
GSLRNG="gsl"
else
GSLRNG=""
fi




{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing getaddrinfo" >&5
$as_echo_n "checking for library containing getaddrinfo... " >&6; }
Expand Down
23 changes: 22 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ AC_ARG_ENABLE([progs],
[AS_HELP_STRING([--enable-progs], [Enable Unicon programs])],
[progs=yes], [progs=no])

AC_ARG_ENABLE([rnglibs],
[AS_HELP_STRING([--enable-rnglibs], [Enable loadable random number generators])],
[rnglibs=yes], [rnglibs=no])

AC_ARG_ENABLE([verbosebuild],
[AS_HELP_STRING([--enable-verbosebuild], [Show full CC build lines with all compiler arguments])],
[verbosebuild=yes], [verbosebuild=no])
Expand Down Expand Up @@ -280,6 +284,11 @@ if test x"$verifyheap" = x"yes" ; then
verifyheapreport="VerifyHeap"
fi

if test x"$rnglibs" = x"yes" ; then
AC_DEFINE([RngLibrary], [1], [Rng Library])
AC_SUBST(RNGLIBS,1)
fi

if test x"$udbtools" = x"yes" ; then
UDBTOOLS=udbtools
fi
Expand Down Expand Up @@ -573,18 +582,30 @@ AC_FUNC_FORK()
AC_CHECK_LIB(dbm,main)
AC_CHECK_LIB(ndbm,main)

# we don't need sqlite to be added to $LIBS, not yet at least
# Check for libs for plugin use, don't add to these to $LIBS
saved_libs="$LIBS"
AC_CHECK_HEADERS([sqlite3.h])
AC_CHECK_LIB(sqlite3, sqlite3_config)

AC_CHECK_HEADERS([gsl/gsl_rng.h])
AC_CHECK_LIB(gsl, gsl_rng_set)

LIBS="$saved_libs"

if test "x$ac_cv_header_sqlite3_h" = "xyes" -a "x$ac_cv_lib_sqlite3_sqlite3_config" = "xyes"; then
SQLITE="sqlite"
else
SQLITE=""
fi

if test "x$ac_cv_header_gsl_gsl_rng_h" = "xyes" -a "x$ac_cv_lib_gsl_gsl_rng_set" = "xyes"; then
GSLRNG="gsl"
else
GSLRNG=""
fi

AC_SUBST(SQLITE)
AC_SUBST(GSLRNG)

AC_SEARCH_LIBS([getaddrinfo],[socket],
[AC_DEFINE([HAVE_GETADDRINFO], [1], [getaddinfo])])
Expand Down
44 changes: 40 additions & 4 deletions doc/book/experimental.tex
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,46 @@ \section{Extensions to \texttt{\&random}}
This feature allows the programmer to choose from a portfolio of different
random number generators (in addition to the one provided by Icon). It is also
possible to implement other generators and use them without rebuilding Unicon.
More than one generator may be in use at the same time.
It may be enabled by defining the C preprocessor symbol \texttt{RngLibrary}
before rebuilding the Unicon system.

More than one generator may be in use at the same time. It may be enabled by
using the \texttt{-{}-enable-rnglibs} option to \texttt{configure} before
rebuilding the Unicon system.

If the extension is enabled four new standard functions are defined:
\bigskip\hrule\vspace{0.1cm}
\noindent
{\bf loadrng(s) : string? } \hfill {\bf load PRNG}

\noindent
\texttt{loadrng(s)} replaces the generator in use by the current thread with the generator
denoted by \texttt{s}. \texttt{loadrng("rngIcon")} will reload the default generator.
\texttt{loadrng()} returns the name of the generator in use. The \texttt{?} operator will
use the loaded generator to produce random numbers.

\bigskip\hrule\vspace{0.1cm}
\noindent
{\bf rngbits(i) : array? } \hfill {\bf return random bits}

\noindent
\texttt{rngbits(n)} returns an integer array that contains at least \texttt{n} randomly
generated bits. If \texttt{n} is negative no bits are returned but the generator will skip
ahead as if the bits were actually returned. If \texttt{n} is zero it is an invitation to
supply the ``natural size'' of the generator (which is probably a power of two).

\bigskip\hrule\vspace{0.1cm}
\noindent
{\bf rngbitstring(i) : string? } \hfill {\bf return random bits}

\noindent
\texttt{rngbitstring(n)} returns a string that contains \texttt{n}
randomly generated \texttt{0} and \texttt{1} characters.

\bigskip\hrule\vspace{0.1cm}
\noindent
{\bf rngval() : integer? } \hfill {\bf return random value}

\noindent
\texttt{rngval()} returns a randomly generated integer value.

\section{Plugins}
\index{Plugins}
Expand Down Expand Up @@ -1046,4 +1083,3 @@ \subsubsection{The \texttt{SQLite} interface routines}
%% \texttt{Close} method.
%%
%----------------------------------------------------------------------

Loading
Loading