basicprogramming.org


Welcome, Guest. Please login or register.
Did you miss your activation email?
Forum time; Jul 31. 2010, 01:51
Home Help Search Calendar Login Register
News: Have you got suggestions for BasicProgramming.org? Let's hear them!
Interested in creating your own programming language? Check out the QDepartment group!

+  BASIC programming forum
|-+  Basic Coding
| |-+  General Basic Programming
| | |-+  Projects.
| | | |-+  Simple RPG
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: 1 2 [3] Go Down Reply Print
Author Topic: Simple RPG  (Read 1141 times)
Derek
Administrator
Hero Member
*****
Offline Offline

Posts: 1001



WWW
« Reply #30 on: Jun 11. 2009, 12:06 » Reply with quote

Hi,

when Yabasic uses ran() for the first time in a script the "random number" isn't very random. The routine randomise() should use ran() enough times to give a "more random" (Ugh, what a phrase!) number. It doesn't appear to work on Linux but the ran() bug is slightly different to the ran() bug on Windows!

I've explained things as best as I can so hopefully someone else can explain it clearer than me.

Derek.
Report to moderator   Logged

wget http://*
JacobN
Guest
« Reply #31 on: Jun 11. 2009, 13:39 » Reply with quote

Alternatively you can implement your own pseudo random number generator, it's fairly straight forward to obtain one that performs almost as well as the one in Yabasic, I haven't tested this one, just wrote it out here, but it's the general idea, and I think I recall writing a similar one at one point... Try it out if you want.

Code:
sub seedrand()
local i, t$, s
t$=time$
for i = 0 to len(t$)
s = mod( s * 2 + asc( mid$( t$, i, 1 ) ), 2 ^ 32 )
next i
return s
end sub

sub getrand( maxval, minval )
static seeded, x, m, c, a, r, k
if( seeded = 0 ) then
seeded = 1
a = 213013
c = 2541011
m = 2^32
k = 1 / ( m + 1 )
x = seedrand()
x = mod( a * x + c, m )
fi
r = mod( a * x + c, m )
x = r
return r * k * ( maxval - minval ) + minval
end sub
Report to moderator   Logged
Katogoon
Newbie
*
Offline Offline

Posts: 14



« Reply #32 on: Jun 11. 2009, 14:18 » Reply with quote

Hi there,

I am not familiar with sub routines yet and not sure how to use them.

Katogoon.
Report to moderator   Logged

I don't suffer from insanity. I enjoy every minute of it.
JacobN
Guest
« Reply #33 on: Jun 11. 2009, 14:33 » Reply with quote

It was actually also more aimed at Derek/People in general because it can be annoying at times when you want something random and the first few numbers always seem to be the same from run to run.
Report to moderator   Logged
Pages: 1 2 [3] Go Up Reply Print 
« previous next »
Jump to:  
Atom RDF RSS 0.91 RSS 2.0


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!