Thanks:  0
Likes:  0
Dislikes:  0

# Thread: Generating Random number beyond 32768

1. ## Generating Random number beyond 32768

Hi Folks!

Long time no-speaky, hope ur all well?

I notice that a seeded random number must be between -32768 and +32768.

Is there a way to shunt this: 0 to 65535?

or preferably up the limit into the millions.

I could generate two random numbers and multiply them together which will give me somewhere between:

0 to 1073741824
but I'm not sure that's the best way.

Any thoughts?

Ta!

------------------
-Colin
colind@profund.com
http://www.profund.com

2. ## Re: Generating Random number beyond 32768

I think that multiplying could skew the 'randomness', but I'm not sure.

What about generating numbers between -32767 to 32768 and adding 32767 to it to shift it right? This would give you 0 to 65535.

To get into the millions, you may need to get random numbers from another source. C++ or better, from files. Looks there is stuff on the web, try http://www.random.org/
------------------
"For words are like prescription lenses; they obscure what they do not make clear."-Stefan Kanfer, Time, 1977

[This message has been edited by drazle (edited 10-14-2002).]

3. ## Re: Generating Random number beyond 32768

Multiplying #'s is no good because you'll never get a prime number. I don't think adding them is optimal either.

Can you make 2 random numbers between 1-9999 and add them together as strings? This way, to get an 8 digit # requires only 2 random #'s, 3 random #'s gets you a random 12 digit #, etc. (I don't have QARun in front of me so I can't verify if/how this would work, but maybe the idea can help).

4. ## Re: Generating Random number beyond 32768

<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by chrisjancic:
Can you make 2 random numbers between 1-9999 and add them together as strings? This way, to get an 8 digit # requires only 2 random #'s, 3 random #'s gets you a random 12 digit #, etc. (I don't have QARun in front of me so I can't verify if/how this would work, but maybe the idea can help).<HR></BLOCKQUOTE>

I just tried this and it works pretty well. Here's what I wrote:

ret1 = Random()
ret2 = Random()

ret1 = StrCat( "" , ret1, ret2 )

;Convert ret1 back to a number
ret1 = val(ret1)

This could end up giving you huge numbers so you might want to put in a default value in the Random functions to limit their output.

------------------

5. ## Re: Generating Random number beyond 32768

Hi Colin!

I notice that a seeded random number must be between -32768 and +32768.

Is there a way to shunt this: 0 to 65535?

Not too hard: add 32768 to it, e.g.
Random(-32767, 32768) + 32768

Second question:
or preferably up the limit into the millions.

I could generate two random numbers and multiply them together which will give me somewhere between:

0 to 1073741824
but I'm not sure that's the best way.

Multiply the first result with 65536.
So:

result = Random(-32767, 32768) + 32768 // Normalized random.
result *= 65536 // Multiply by 65536
result += Random(-32767, 32768) + 32768 // Add another normalized random.

So the result will be in the range
0 to 65536 * 65535 + 65535 =
0 to 4294967295 ( = 2^32 - 1)

------------------

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 9.09%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 07:23 AM.