summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote
diff options
context:
space:
mode:
authorMojca Miklavec <mojca.miklavec@gmail.com>2014-05-21 10:08:33 +0000
committerMojca Miklavec <mojca.miklavec@gmail.com>2014-05-21 10:08:33 +0000
commitdfae4647ee373628620ebb330646b2e1879de010 (patch)
treeb7c919fe0bbc6a1e6e0857a3fcf17c68983e0bdd /Build/source/utils/asymptote
parent783a761a9c97d8ba7360183ff19f3fa5c34cb7ef (diff)
asymptote: fix random numbers on platforms like Solaris (with 16-bit RAND_MAX and 32-bit random())
git-svn-id: svn://tug.org/texlive/trunk@34169 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote')
-rw-r--r--Build/source/utils/asymptote/builtin.cc2
-rw-r--r--Build/source/utils/asymptote/common.h2
-rw-r--r--Build/source/utils/asymptote/drawlabel.cc4
-rw-r--r--Build/source/utils/asymptote/runmath.in2
-rw-r--r--Build/source/utils/asymptote/tests/arith/random.asy11
5 files changed, 17 insertions, 4 deletions
diff --git a/Build/source/utils/asymptote/builtin.cc b/Build/source/utils/asymptote/builtin.cc
index acb84eb2bd0..75c29e775a4 100644
--- a/Build/source/utils/asymptote/builtin.cc
+++ b/Build/source/utils/asymptote/builtin.cc
@@ -873,7 +873,7 @@ void base_venv(venv &ve)
addConstant<double>(ve, DBL_MIN, primReal(), SYM(realMin));
addConstant<double>(ve, DBL_EPSILON, primReal(), SYM(realEpsilon));
addConstant<Int>(ve, DBL_DIG, primInt(), SYM(realDigits));
- addConstant<Int>(ve, RAND_MAX, primInt(), SYM(randMax));
+ addConstant<Int>(ve, RANDOM_MAX, primInt(), SYM(randMax));
addConstant<double>(ve, PI, primReal(), SYM(pi));
addConstant<string>(ve, string(settings::VERSION)+string(SVN_REVISION),
primString(),SYM(VERSION));
diff --git a/Build/source/utils/asymptote/common.h b/Build/source/utils/asymptote/common.h
index 5d41285f79e..c9ca914a326 100644
--- a/Build/source/utils/asymptote/common.h
+++ b/Build/source/utils/asymptote/common.h
@@ -73,6 +73,8 @@ typedef unsigned int unsignedInt;
#define int_MIN LONG_MIN
+#define RANDOM_MAX 0x7FFFFFFF
+
using std::cout;
using std::cin;
using std::cerr;
diff --git a/Build/source/utils/asymptote/drawlabel.cc b/Build/source/utils/asymptote/drawlabel.cc
index e887879b52d..1baaf18fe57 100644
--- a/Build/source/utils/asymptote/drawlabel.cc
+++ b/Build/source/utils/asymptote/drawlabel.cc
@@ -66,8 +66,8 @@ void texbounds(double& width, double& height, double& depth,
inline double urand()
{
- static const double factor=2.0/RAND_MAX;
- return rand()*factor-1.0;
+ static const double factor=2.0/RANDOM_MAX;
+ return random()*factor-1.0;
}
void setpen(iopipestream& tex, const string& texengine, const pen& pentype)
diff --git a/Build/source/utils/asymptote/runmath.in b/Build/source/utils/asymptote/runmath.in
index c7b2ef217dd..ea74462bc2b 100644
--- a/Build/source/utils/asymptote/runmath.in
+++ b/Build/source/utils/asymptote/runmath.in
@@ -115,7 +115,7 @@ void srand(Int seed)
// a random number uniformly distributed in the interval [0,1]
real unitrand()
{
- return ((real) random())/RAND_MAX;
+ return ((real) random())/RANDOM_MAX;
}
Int ceil(real x)
diff --git a/Build/source/utils/asymptote/tests/arith/random.asy b/Build/source/utils/asymptote/tests/arith/random.asy
new file mode 100644
index 00000000000..c972744da4f
--- /dev/null
+++ b/Build/source/utils/asymptote/tests/arith/random.asy
@@ -0,0 +1,11 @@
+import TestLib;
+StartTest("random");
+bool bit32=false;
+for(int i=0; i < 1000; ++i) {
+ real x=unitrand();
+ if(x > 0.5) bit32=true;
+ assert(x >= 0.0 && x <= 1.0);
+}
+assert(bit32);
+
+EndTest();