Qbasicnews.com

Full Version: Re-seeding issue in FB
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

I am attempting to implement re-seeding technigue. I posted the same at QB in General section. Mac suggested the code as below:
Code:
CLS
DO
  RANDOMIZE TIMER
  seed = RND * 999999
  y = RND(-seed)
  FOR i = 1 TO 5: PRINT RND; : NEXT i: PRINT
  y = RND(-seed)
  FOR i = 1 TO 5: PRINT RND; : NEXT i: PRINT
  INPUT "Again"; a$
LOOP WHILE LEFT$(UCASE$(a$ + " "), 1) = "Y"
CLS
SYSTEM

It works in QB but not so in FB. Any suggestion?

TIA Smile

Geo
here's a fairly simple qb-rnd emulator function that will work with fb. it should be the same as qb's rnd output. (i haven't tested this very much, so watch out...)

Code:
declare function rnd2#(a as integer=0)

for i = 1 to 9
   a#=rnd2#
   print a#*16777216;a#
next
sleep

function rnd2#(a as integer=0) ' ***** ***** This is the number produced by zombie
static seed#,ft as byte
if ft=0 then seed#=327680:ft=1
if a<>0 then
   if a=abs(a) then seed#=(seed#+a) mod 16777216 else seed#=-a
end if
Temp# = (16598013# * Seed# + 12820163)
Seed# = Temp# - INT(Temp# / 16777216) * 16777216
rnd2#=seed#/16777216
end function
actually, fb's randomize statement works different that qb's, so you could just say
Code:
CLS
DO
  RANDOMIZE TIMER
  seed = RND * 999999
  RANDOMIZE seed
  FOR i = 1 TO 5: PRINT RND; : NEXT i: PRINT
  RANDOMIZE seed
  FOR i = 1 TO 5: PRINT RND; : NEXT i: PRINT
  INPUT "Again"; a$
LOOP WHILE LEFT$(UCASE$(a$ + " "), 1) = "Y"
CLS
SYSTEM
Thanks, dumbledore!

I prefer your second version. The code looks more sense and cleaner than that of QB version.

Geo
Yeah, as shown at docs/keywords.txt, negative arguments with RND have no means in FB.