winzip icon

Fast pure VB Random numbers, and Shift and Rotate 32 and 64 bit

Submitted on: 4/16/2020 8:14:54 AM
By: Rde 
Level: Intermediate
User Rating: By 2 Users
Compatibility: VB 5.0, VB 6.0
Views: 7530
author picture

Powerful Pure VB Technique

Sorry, second bug fix update April 16, 2020

This is 4 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. This is now so fast and easy.

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.

See Changes.txt.

This post now includes Fast pure VB Shift and Rotate 32-bit and 64-bit

Traditional shifting in VB requires quite convoluted conditionals, multiplication and masking to accomplish what is a simple operation in most other languages. The downside is these operations are relatively slow.

Until now! These pure VB routines are fast!

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 25 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 Intermediate 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
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.)

4/15/2020 7:29:22 AMRde

This update is very much a collaboration with Kenneth Ives
64-bit shift and rotate easy to add
(If this comment was disrespectful, please report it.)

4/22/2020 5:42:10 PMPaul Bahlawan

Just .bas files? No demo project?
(If this comment was disrespectful, please report it.)

4/22/2020 7:57:08 PMRde

hi Paul

I could probably get a demo of some sort for you

A silly dice rolling demo using random number generator

Or perhaps CRC 32 using bit shifting, no probs

Enter a number and use bit shift to display the binary zeroes and ones?

Or something more practical and useful, something you need?

Let me know any suggestions welcome

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

4/23/2020 1:13:46 PMPaul Bahlawan

Lol rde! Your codes are often advanced beyond my comprehension, so some blinking lights would entertain me :)
(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.