Qbasicnews.com
April 12, 2021, 07:55:08 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: 1 [2]
  Print  
Author Topic: Fiddling around with random #s and odds.  (Read 15174 times)
Antoni Gual
Na_th_an
*****
Posts: 1434



WWW
« Reply #15 on: January 11, 2007, 07:45:59 PM »

RND used  the OS's C runtime rand function until version 0.17 jun-30 unstable. The rand function in Windows'  library has a granularity of just 15 bits, so probably it is unable of generating exactly 1234567. For comparison QB's RND has 24 bits granularity.

In the present version compiled from CVS  you have a different RND depending on the -lang option passed in the command line of the compiler:
With -lang qb you have a RND mimicking exactly QB's generator.
With -lang fb (the default) you have a Mersenne Twister algorithm with 32 bits granularity.
With -lang deprecated it behaves as 0.16 version, using C runtime's rand

You have too a fourth "fast" random algorithm and a second argument to RANDOMIZE allowing to select the algorithm used...

So perhaps some of you updated to the CVS version, it would explain why you get 1234567. Or you are using the DOS or Linux version where the granularity of rand is 31 bits..

More in the wiki:
http://www.freebasic.net/wiki/wikka.php?wakka=KeyPgRnd
Logged

Antoni
Moneo
Na_th_an
*****
Posts: 1971


« Reply #16 on: January 11, 2007, 10:26:27 PM »

Quote from: "Skyler"
That's what happens when you run Windows...
:sigh:

Skyler,
Why don't you ever offer some technical feedback, comments, or ideas to threads? It seems like all you do is kibitz.

*****
Logged
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #17 on: January 12, 2007, 12:57:16 AM »

Quote from: "Antoni Gual"
RND used  the OS's C runtime rand function until version 0.17 jun-30 unstable. The rand function in Windows'  library has a granularity of just 15 bits, so probably it is unable of generating exactly 1234567. For comparison QB's RND has 24 bits granularity.

In the present version compiled from CVS  you have a different RND depending on the -lang option passed in the command line of the compiler:
With -lang qb you have a RND mimicking exactly QB's generator.
With -lang fb (the default) you have a Mersenne Twister algorithm with 32 bits granularity.
With -lang deprecated it behaves as 0.16 version, using C runtime's rand

You have too a fourth "fast" random algorithm and a second argument to RANDOMIZE allowing to select the algorithm used...

So perhaps some of you updated to the CVS version, it would explain why you get 1234567. Or you are using the DOS or Linux version where the granularity of rand is 31 bits..

More in the wiki:
http://www.freebasic.net/wiki/wikka.php?wakka=KeyPgRnd

1234567=(x*2000000)+1
x=1234566/2000000
x=0.617283
So you're saying that my version of FB is unable to generate 0.617283 because the RND function doesn't generate numbers to that precision?
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
TheAdventMaster
Ancient Guru
****
Posts: 671


« Reply #18 on: January 12, 2007, 01:54:47 AM »

I'm on windows, and I ran it like 10 times.  Each time passed within a second or less.  It works just fine here.
Logged
Antoni Gual
Na_th_an
*****
Posts: 1434



WWW
« Reply #19 on: January 12, 2007, 05:07:34 AM »

Did you ever installed one of the updates mintained by Eric Cowles (1000101) or before November, by Pritchard? If you did that you are using  the new RND
Logged

Antoni
TheAdventMaster
Ancient Guru
****
Posts: 671


« Reply #20 on: January 12, 2007, 08:47:39 AM »

Quote from: "Antoni Gual"
Did you ever installed one of the updates mintained by Eric Cowles (1000101) or before November, by Pritchard? If you did that you are using  the new RND
Thx.  Had no idea rnd was even changed.
Logged
Antoni Gual
Na_th_an
*****
Posts: 1434



WWW
« Reply #21 on: January 12, 2007, 10:00:02 AM »

Quote from: "Zack"

So you're saying that my version of FB is unable to generate 0.617283 because the RND function doesn't generate numbers to that precision?


Yes, and not only your version of FB, also  the Visual C compilers by Microsoft. It's how msvcrt71.dll works. QB had more precission.

It has been documented in the wiki for a year, and updated recently to cover  version 0.17, as this version is close to be released.
Logged

Antoni
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #22 on: January 12, 2007, 02:46:14 PM »

That's what I get for belittling CVS. Thanks Antoni.
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
DrV
Na_th_an
*****
Posts: 1553



WWW
« Reply #23 on: January 13, 2007, 06:14:58 PM »

Part of the problem is that the C library's rand() (which was used by the old RND) returns an integer (up to 2^16 with the MSVCRT runtime, if I remember right), which FB then converts to a floating-point value, which you then convert back to an integer...
Logged
TheAdventMaster
Ancient Guru
****
Posts: 671


« Reply #24 on: January 13, 2007, 07:10:54 PM »

Quote from: "DrV"
Part of the problem is that the C library's rand() (which was used by the old RND) returns an integer (up to 2^16 with the MSVCRT runtime, if I remember right), which FB then converts to a floating-point value, which you then convert back to an integer...


4 -> .000032 -> 0
2811 -> .0003984 -> 0 . . . .

lol Tongue
Logged
Pages: 1 [2]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!