View Issue Details
ID  Project  Category  View Status  Date Submitted  Last Update 

0000945  MetaPost  bug  public  20150816 17:30  20151006 12:39 
Reporter  toby  Assigned To  
Priority  normal  Severity  minor  Reproducibility  always 
Status  new  Resolution  open  
Product Version  1.890  
Summary  0000945: New number systems: "uniformdeviate 4096" produces integers instead of reals  
Description  Using mpost recently compiled from trunk, I get odd results from "uniformdeviate"  "uniformdeviate 1" produces numbers that are all multiples of 1/4096.  "uniformdeviate 1024" produces multiples of 1/4  "uniformdeviate 4096" produces integers  "uniformdeviate 8092" produces even integers and so on I guess that this is another artefact from the conversion from the scaled routines. Maybe we need a new uniform random number generator for each of the new number systems?  
Steps To Reproduce  show numbersystem; warningcheck := 0; for i=1 upto 4: x := uniformdeviate 4096; show x; endfor  
Additional Information  Here's some sample output from the above, with each of the number systems This is MetaPost, version 1.999 (TeX Live 2015) (kpathsea version 6.2.1) (/usr/local/texlive/2014/texmfdist/metapost/base/mpost.mp (/usr/local/texlive/2014/texmfdist/metapost/base/plain.mp Preloading the plain mem file, version 1.005) ) (./numbers.mp >> "scaled" >> 3197.13828 >> 2188.96832 >> 3010.09789 >> 3947.62305 ) Transcript written on numbers.log. This is MetaPost, version 1.999 (TeX Live 2015) (kpathsea version 6.2.1) (/usr/local/texlive/2014/texmfdist/metapost/base/mpost.mp (/usr/local/texlive/2014/texmfdist/metapost/base/plain.mp Preloading the plain mem file, version 1.005) ) (./numbers.mp >> "double" >> 917 >> 67 >> 1353 >> 814 ) Transcript written on numbers.log. This is MetaPost, version 1.999 (TeX Live 2015) (kpathsea version 6.2.1) (/usr/local/texlive/2014/texmfdist/metapost/base/mpost.mp (/usr/local/texlive/2014/texmfdist/metapost/base/plain.mp Preloading the plain mem file, version 1.005) ) (./numbers.mp >> "binary" >> 2678 >> 3060 >> 367 >> 2208 ) Transcript written on numbers.log. This is MetaPost, version 1.999 (TeX Live 2015) (kpathsea version 6.2.1) (/usr/local/texlive/2014/texmfdist/metapost/base/mpost.mp (/usr/local/texlive/2014/texmfdist/metapost/base/plain.mp Preloading the plain mem file, version 1.005) ) (./numbers.mp >> "decimal" >> 2270 >> 3804 >> 735 >> 1264 ) Transcript written on numbers.log.  
Tags  No tags attached.  

Looking at the source, code I see that we are still using the base random number generator which does indeed generate "fractions", which is why they come out as 1/4096s I guess. Is it too much work to override the whole mechanism? TAOCP 3.6 gives a suitable highlevel language routine (albeit in Fortran). 

Thank you for the report. I will look at it asap. 

take_fraction is specialized for each numbersystem, so it should be ok. 

yes but you are using 1/4096 as the resolution in the random number generator instead of 2^28 as in the original because of the way you have implemented take_fraction for decimal. So the random numbers are not very random. Perhaps it would be better to rewrite the random number generator *without* fractions? (But I can see that this would make a bunch more work elsewhere). 

I think that I have to make a mp_unif_rand specific for each numbersystem. 

http://wwwcsfaculty.stanford.edu/~uno/programs/rng.c could be a good choice. 

I have adapted rng.c for binary, decimal and double (trivial modifications). Now the uniform random generator has a modulo of 2^30 and a period of (2^30)^21=2^601. I will commit soon. 

Revision 2069 still has the old generator. 

Rev. 2070 has new generator. 
Date Modified  Username  Field  Change 

20150816 17:30  toby  New Issue  
20150817 16:57  toby  Note Added: 0001397  
20150914 18:20  luigi scarso  Note Added: 0001403  
20150914 21:43  luigi scarso  Note Added: 0001405  
20150914 23:59  toby  Note Added: 0001406  
20150916 00:40  luigi scarso  Note Added: 0001407  
20150918 10:29  luigi scarso  Note Added: 0001408  
20150922 11:50  luigi scarso  Note Added: 0001410  
20150923 12:40  luigi scarso  Note Added: 0001411  
20151006 12:39  luigi scarso  Note Added: 0001413 