From: David B. <Dav...@mo...> - 2005-04-11 11:37:36
|
I was recently required to reproduce the same sequence of random numbers in octave and matlab to demonstrate bit accurate simulation between two versions of the same simulator (one under octave and the other under matlab). My means of doing this was to replace the matlab rand/randn functions with ones based on the code from octave-forge. I attach the mexFunction to allow this to this message in case others find themselves in the same position. There are a couple of points to note. 1) You must obtain randmtzig.c from octave-forge 2) The compile flag will be dependent on the machine but to compile the code for matlab under x86 linux I used "mex -O -DEXPORT -DALLBITS -DUSE_X86_32=1 rand.c" 3) The mexFunction should either be copied or symbolically linked to randn mexFunction (under linux randn.mexglx) 4) The octave-forge versions of rand.oct and rand.oct must NOT be a symbolic link from one to the other. This ensures that the two random function use separate instantiations of the Mersenne Twister. This is not the case for a standard install of octave-forge and so again rand.oct and randn.oct should be copied. 5) Both rand and randn must be seeded separately at the start of the simulation since they use seperate instantiations of the Mersenne Twister Enjoy David -- David Bateman Dav...@mo... Motorola Labs - Paris +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin +33 1 69 35 77 01 (Fax) 91193 Gif-Sur-Yvette FRANCE The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary |