Liberty BASIC Community Forum
« right$() rnd(0) »

Welcome Guest. Please Login or Register.
Mar 19th, 2018, 09:25am

Rules|Home|Help|Search|Recent Posts|Notification

Problems installing Liberty BASIC? Read the Vista/Win7 Installation FAQ
Looking for a categorized List of Bug Reports? Visit the Liberty BASIC Bug Tracker

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: right$() rnd(0)  (Read 59 times)
Global Moderator

member is online


Graphics = goosebumps!


Gender: Male
Posts: 5706
xx right$() rnd(0)
« Thread started on: Feb 28th, 2018, 03:37am »

This line of code will fail randomly with an index outside bounds error. It seems to be the combination of right$() and the nesting of rnd(). Left$ and mid$ don't exhibit the problem. Splitting out the rnd() function solves the problem.

for rec= 1 to 100
    print rec

Bug goes back to 4.04, don't know how we missed it for so long :)
« Last Edit: Feb 28th, 2018, 03:39am by Rod » User IP Logged

Board Moderator

member is offline


Anatoly (real name)


Gender: Male
Posts: 1748
xx Re: right$() rnd(0)
« Reply #1 on: Feb 28th, 2018, 07:02am »

I don't know what is going on
but while testing I found that using RIGHT$, LEFT$ somehow advances RND sequence (like it is called several times).
I tried stuff user-defined function with side effects (printing) but it doesn't got called several times. (???)
I hope that might offer some clue to Carl.
randomize .8
for i = 1 to 10
    print i, int(rnd(0)*9999)

print "Now try use some string functions on same rnd"
print "right$ - !! get every SECOND rnd, last digit chopped"
randomize .8    'so it starts the same
'sorry it died with 0.3, 0.4, ...0.7
for i = 1 to 10
    print i, right$(str$(int(rnd(0)*9999)), 4) '!! get every SECOND rnd

print "left$ - !! get every THIRD rnd"
randomize .8    'so it starts the same
for i = 1 to 10
    print i, left$(str$(int(rnd(0)*9999))+ "0000", 4)  '!! get every THIRD rnd

changing STR$() to Code:
doesn't make any difference.

wrapping any of RND, STR, RIGHT in user-defined function, like
function myrnd(dummy)
    myrnd = rnd(0)
end function 

removes original problem and RND advancing.
« Last Edit: Feb 28th, 2018, 07:31am by tsh73 » User IP Logged

damned Dog in the Manger
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Liberty BASIC Community Wiki
| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls