Author Topic: Random Numbers  (Read 4992 times)

0 Members and 1 Guest are viewing this topic.

Offline Taylorover9001

  • Newbie
  • Posts: 6
    • View Profile
Random Numbers
« on: April 05, 2018, 09:52:40 pm »
Why does random number generation suck in QB64? No matter what tricks and randomization stuff I do, it often doesn't feel right.

FellippeHeitor

  • Guest
Re: Random Numbers
« Reply #1 on: April 05, 2018, 10:51:59 pm »
Random number generation will go as far as QuickBASIC's would.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Random Numbers
« Reply #2 on: April 05, 2018, 10:53:15 pm »
Perhaps you could provide a few code examples where things "feel" wrong?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Random Numbers
« Reply #3 on: April 06, 2018, 02:08:59 pm »
I see pretty good spread of dots over the screen, no particularly dark or light spots or sections which would suck.

With magnifying glass, I see craters and even a few canals.

Code: QB64: [Select]
  1. _TITLE "RND test by bplus 2018-04-04"
  2. 'QB64 version 2017 1106/82 (the day before they switched to version 1.2)
  3.  
  4.  
  5. 'Looking for fairly even spread of dots
  6.  
  7.  
  8. CONST xmax = 800
  9. CONST ymax = 600
  10. SCREEN _NEWIMAGE(xmax, ymax, 32)
  11. _SCREENMOVE 360, 60
  12. screenfull = xmax * ymax
  13. COLOR _RGBA32(255, 255, 255, 15)
  14. FOR i = 1 TO screenfull * 10
  15.     x = xmax * RND
  16.     y = ymax * RND
  17.     PSET (x, y)
  18. _TITLE "Test Done!!!!!!"
  19.  
  20.  


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Random Numbers
« Reply #4 on: April 06, 2018, 07:30:34 pm »
Here is a built in magnifying view finder, maybe you can find a man on the moon or Waldo.

Code: QB64: [Select]
  1. _TITLE "RND test by bplus 2018-04-04"
  2. 'QB64 version 2017 1106/82 (the day before they switched to version 1.2)
  3.  
  4.  
  5. 'Looking for fairly even spread of dots
  6.  
  7.  
  8. CONST xmax = 800
  9. CONST ymax = 600
  10. SCREEN _NEWIMAGE(xmax, ymax, 32)
  11. _SCREENMOVE 360, 60
  12. screenfull = xmax * ymax
  13. COLOR _RGBA32(255, 255, 255, 15)
  14. DIM magnify(xmax, ymax)
  15. FOR i = 1 TO screenfull * 10
  16.     x = xmax * RND
  17.     y = ymax * RND
  18.     PSET (x, y)
  19.     magnify(x, y) = magnify(x, y) + 1
  20. _TITLE "Sceen Test Done"
  21.  
  22. 'make sure my viewer is aligned right by using a black line in the middle of screen
  23. FOR i = -15 TO 15
  24.     magnify(xmax / 2, ymax / 2 + i) = 0
  25.  
  26. LOCATE 15, 10
  27. INPUT " OK press enter to see mouse over x, y  40 x 30 block magnfied."; magnify$
  28.  
  29.     CLS
  30.     FOR y = 0 TO 600
  31.         FOR x = 0 TO 800
  32.             COLOR _RGB32(magnify(x, y) * 15, magnify(x, y) * 15, magnify(x, y) * 15)
  33.             PSET (x, y)
  34.         NEXT
  35.     NEXT
  36.  
  37.         mx = _MOUSEX
  38.         my = _MOUSEY
  39.     LOOP
  40.  
  41.     IF mx > 20 AND mx < 780 AND my > 15 AND my < 585 THEN
  42.         COLOR _RGB32(0, 0, 0)
  43.         LINE (mx - 20, my - 15)-(mx + 20, my + 15), , B
  44.         FOR y = -15 TO 15
  45.             FOR x = -20 TO 20
  46.                 COLOR _RGB32(magnify(mx + x, my + y) * 15, magnify(mx + x, my + y) * 15, magnify(mx + x, my + y) * 15)
  47.                 LINE (5 * (x + 20), 5 * (y + 15))-STEP(5, 5), , BF
  48.             NEXT
  49.         NEXT
  50.     END IF
  51.     _TITLE "Mouse x" + STR$(mx) + ", Mouse y" + STR$(my) + "       press spacebar to quit."
  52.     _DISPLAY
  53.     _LIMIT 60
  54.  
  55.  

Offline Bert22306

  • Forum Regular
  • Posts: 206
    • View Profile
Re: Random Numbers
« Reply #5 on: April 06, 2018, 09:41:08 pm »
Yeah, I also wrote a "dots on screen" test, plus a histogram test to show occurrences in 10 separate bins, as well as min, max, and mean, and these tests look good. Nothing obviously bad about the built-in PRNG, even if the seed is only something like 24 bits wide.

Why do you think it sucks?

FellippeHeitor

  • Guest
Re: Random Numbers
« Reply #6 on: April 06, 2018, 10:40:07 pm »
Here is a built in magnifying view finder, maybe you can find a man on the moon or Waldo.

That was neat bplus!