MantisBT

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0000945MetaPostbugpublic2015-08-16 17:302015-10-06 12:39
Reportertoby 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusnewResolutionopen 
PlatformOSOS Version
Product Version1.890 
Target VersionFixed in Version 
Summary0000945: New number systems: "uniformdeviate 4096" produces integers instead of reals
DescriptionUsing 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 Reproduceshow numbersystem;
warningcheck := 0;
for i=1 upto 4:
  x := uniformdeviate 4096;
  show x;
endfor
Additional InformationHere'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/texmf-dist/metapost/base/mpost.mp
(/usr/local/texlive/2014/texmf-dist/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/texmf-dist/metapost/base/mpost.mp
(/usr/local/texlive/2014/texmf-dist/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/texmf-dist/metapost/base/mpost.mp
(/usr/local/texlive/2014/texmf-dist/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/texmf-dist/metapost/base/mpost.mp
(/usr/local/texlive/2014/texmf-dist/metapost/base/plain.mp
Preloading the plain mem file, version 1.005) ) (./numbers.mp
>> "decimal"
>> 2270
>> 3804
>> 735
>> 1264 )
Transcript written on numbers.log.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0001397)
toby (reporter)
2015-08-17 16:57

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 high-level language routine (albeit in Fortran).
(0001403)
luigi scarso (manager)
2015-09-14 18:20

Thank you for the report. I will look at it asap.
(0001405)
luigi scarso (manager)
2015-09-14 21:43

take_fraction is specialized for each numbersystem, so it should be ok.
(0001406)
toby (reporter)
2015-09-14 23:59

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 re-write the random number generator *without* fractions? (But I can see that this would make a bunch more work elsewhere).
(0001407)
luigi scarso (manager)
2015-09-16 00:40

I think that I have to make a mp_unif_rand specific for each numbersystem.
(0001408)
luigi scarso (manager)
2015-09-18 10:29

http://www-cs-faculty.stanford.edu/~uno/programs/rng.c [^] could be a good choice.
(0001410)
luigi scarso (manager)
2015-09-22 11:50

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)^2-1=2^60-1. I will commit soon.
(0001411)
luigi scarso (manager)
2015-09-23 12:40

Revision 2069 still has the old generator.
(0001413)
luigi scarso (manager)
2015-10-06 12:39

Rev. 2070 has new generator.

- Issue History
Date Modified Username Field Change
2015-08-16 17:30 toby New Issue
2015-08-17 16:57 toby Note Added: 0001397
2015-09-14 18:20 luigi scarso Note Added: 0001403
2015-09-14 21:43 luigi scarso Note Added: 0001405
2015-09-14 23:59 toby Note Added: 0001406
2015-09-16 00:40 luigi scarso Note Added: 0001407
2015-09-18 10:29 luigi scarso Note Added: 0001408
2015-09-22 11:50 luigi scarso Note Added: 0001410
2015-09-23 12:40 luigi scarso Note Added: 0001411
2015-10-06 12:39 luigi scarso Note Added: 0001413


Copyright © 2000 - 2012 MantisBT Group
Powered by Mantis Bugtracker