">

winzip icon

Pure VB very fast MOA random numbers [Update 4]

Email
Submitted on: 12/19/2016 2:05:51 PM
By: Rde 
Level: Advanced
User Rating: By 1 Users
Compatibility: VB 5.0, VB 6.0
Views: 2476
author picture
 
     

Powerful Pure VB Technique

This is 3 small VB modules that demonstrate a
rarely used but very powerful technique that
allow easy and fast multi-data-type transfers.

By using some simple UDT declarations you can
copy different data types from one to another
with no overhead and lightning fast too!

The secret is no secret at all, but is so rarely
seen you would think it was a secret - LSet.

This code demonstrates copying a Long to Currency
to allow unsigned arithmetic with no worries about
overflow or signed Long integer trouble. It then
copies the data back just as quickly and easily.

The most code efficient VB unsigned arithmetic ever!
This module now includes more detailed explanation.

A second small module demonstrates shifting bits.
Bit shifting is not a built-in operation in VB,
requiring multiplication, division and masking to
get the job done. If the shift is a multiple of
8 bits, this is now so fast and easy.

Just copy the low integer to the high integer and
zero the low to perform an 16-bit shift to the left.
Or copy the high integer to the low integer and zero
the high to perform an 16-bit shift to the right.

For rotations just simply copy one integer out, copy
the other over, then the first one back in.

Shifts in a multiple of 8-bits can be done for 16-bit
up to 64-bit data types using bytes, ints or longs,
all with code so simple and exceptionally fast too.

These techniques are demonstrated in another module
that performs Random Number Generation based on the
Mother Of All algorithm created by George Marsaglia.

This algo is truly fast with unbeatable output.
  • Update 1: Improved demo modules.
  • Update 2: Tweaked generator for more speed!
  • Update 3: Modified InitSeed behavior.
  • Update 4: Fixed bug in RandomRange.
See Changes.txt.

 
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com


Other 15 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

12/16/2016 1:53:43 PMRobert Dee

Rde, this is interesting. I was most interested in the bit shifting module but it seems to be missing - or I just can't see it. Thanks for your efforts.
(If this comment was disrespectful, please report it.)

 
12/17/2016 2:51:35 AMRde

Hi Rob
Thanks for your interest in
my bit-shifting submission.
I realize I didn't give much
explanation on this technique
so I have added much needed
comments and more code, plus
an extra module to demo these
techniques.
Hope this helps and thanks :)

(If this comment was disrespectful, please report it.)

 
12/18/2016 8:33:09 AMRde

Known bug
RandomRange can only handle positive values
between 1 and 2147483647
(If this comment was disrespectful, please report it.)

 
12/19/2016 2:09:52 PMRde

Bug mentioned above is now fixed
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.