LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default RNG translation

Can someone translate the code below to VBA?

TIA


/*

COMBO

a simple but very good combination generator.
It combines, by addition mod 2^32,
x(n)=x(n-1)*x(n-2) mod 2^32
and
y(n)=30903*y(n-1) + carry mod 2^16
The period of the first is 3*2^29, on odd integers, and the
period of the second, a multiply-with-carry generator, is
30903*2^15-1=1012629503, so the period of combo exceeds 2^60.
This generator is simple to program in Fortran or C and quite
fast.

*/

/*
Simple combo, period 2^60.5
x(n)=x(n-1)*x(n-2) mod 2^32 added to
period of x(n)=x(n-1)*x(n-2) is 3*2^29 if both seeds are
odd, and one is +or-3 mod 8.
easy to ensu replace seed x with 8*seed+3, and y with 2*seed+1
*/


#define ulong unsigned long

static ulong combo_x = 3;
static ulong combo_y = 1;
static ulong combo_z = 1;
static ulong combo_v;

void seed_rand_combo(ulong seed) {
combo_x = seed * 8 + 3;
combo_y = seed * 2 + 1;
combo_z = seed | 1;
}

ulong rand_combo(void) {
combo_v = combo_x * combo_y;
combo_x = combo_y;
combo_y = combo_v;
combo_z = (combo_z & 65535) * 30903 + (combo_z 16);
return combo_y + combo_z;
}
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Language Translation Barbara Ann Excel Discussion (Misc queries) 3 November 27th 07 01:37 AM
Code translation please N.F[_2_] Excel Discussion (Misc queries) 0 July 6th 07 12:42 AM
column value translation charles New Users to Excel 7 June 15th 06 09:12 PM
Translation Exercise ... Rebecca Excel Worksheet Functions 9 June 6th 06 09:18 PM
Need Translation Phil Hageman Excel Programming 1 July 25th 03 03:19 PM


All times are GMT +1. The time now is 11:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"