Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / random that isn't random

Author
Message
freak
22
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 22nd Jan 2003 01:31
I'm working at a playing cards game.
Here's the script in which I set up a random deck of cards when the game's started.
When you run this script in DB, you'll see some random numbers. But when you quit the program and re-run it, you'll see the same "random" row of numbers...
This is something that shouldn't be possible I think, I hope I was the one that made a mestake and not DB. Someone who knows what's happening?

Here is the code:

main program:
begin:
gosub initialise
gosub randomdeck
gosub test_deck

wait key
cls
goto begin
end
gosubs:
initialise:
hide mouse
dim deck(100)
return

`---------------------------------------------------------------------------

randomdeck:
dim deck(52)
cardnr=1
while cardnr
freak
22
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 22nd Jan 2003 01:34
I'm having some problems working with this forum...

I thought the " [ code ] " tags would make a little link to let code pop-up but that doens't seem to work...

and I posted more lines but they aren't all shown... there seems to be a limit

anyway I opened this thread twice by accident, can a mod please remove the other one? thx

freak
22
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 22nd Jan 2003 01:35
ok, here's my code (3rd try):

begin:
gosub initialise
gosub randomdeck
gosub test_deck

wait key
cls
goto begin
end

freak
22
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 22nd Jan 2003 01:36
here are the sub's:

initialise:
hide mouse
dim deck(100)
return

randomdeck:
dim deck(52)
cardnr=1
while cardnr<53
newrndnr:
test=rnd(51)+1
fout=0
for t=1 to cardnr
if deck(t)=test then fout=1
next t
if fout=1 then goto newrndnr
if fout=0 then deck(cardnr)=test
inc cardnr
endwhile
return

freak
22
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 22nd Jan 2003 01:37
and this is the last sub:

test_deck:
cardnr=1
for u=1 to 3
for t=1 to 20
set cursor 200+u*40,t*20
if cardnr<53 then print deck(cardnr)
inc cardnr
next t
next u
return

Easily Confused
22
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 22nd Jan 2003 01:38
To make sure you get true random numbers from the Rnd() command place Randomize Timer() at the top of your program.

Programming anything is an art, and you can't rush art.
Unless your name is Bob Ross, then you can do it in thirty minutes.
Richard Davey
Retired Moderator
23
Years of Service
User Offline
Joined: 30th Apr 2002
Location: On the Jupiter Probe
Posted: 22nd Jan 2003 01:38
Put the [ code ] tag on a line of its own (and the closing one) and then your code in the middle. Most of the time it will work fine.

As for making random numbers random you need to seed the random number generator first. This will ensure a truly random set each time - it's not hard to do, try this:

randomize timer()

This will use the timer to re-seed the random number generator.

Simple really

Cheers,

Rich

"Gentlemen, we are about to short-circuit the Universe!"
DB Team / Atari ST / DarkForge / Retro Gaming
freak
22
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 22nd Jan 2003 01:47
awesome to have such fast replies!
yep, it works, thanks, this saved me much time as I was already thinking of trying to program my own random number generator

here's a screenshot of the game I'm working at (I hope this tag works )


As you might see, there's a little problem with the most distant group of cards: it seems that surfaces that are really close to eachother are drawn trough eachother when you look at them under a certain angle...
Offcourse this is not what I want, you can see the cards of the player in front of you...

Anyone knows a solution to this problem?

Dr DooMer
22
Years of Service
User Offline
Joined: 22nd Dec 2002
Location: United Kingdom
Posted: 22nd Jan 2003 03:20
It's a problem with your ZDepth - the easiest way to solve it would be to seperate out the cards a bit more. Of course, you could delve into the possibilites of "set camera range" and rescaling everything a bit, but you probably won't want to mess with that at the moment.

By the way, the game looks promising! It's always nice to find a new user who doesn't immediately think he can program a commercial-quality MMRPG or something. Good luck with your project!

"I am a living, thinking entity who was created in the sea of information."
freak
22
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 22nd Jan 2003 13:50
quote:
It's always nice to find a new user who doesn't immediately think he can program a commercial-quality MMRPG or something. Good luck with your project!

Thanks doomer!
I didn't really try to make a MMRPG, but this is also quite complex... It's the longest script I ever wrote, almost 1000 lines, but I have a lot more to do.

quote:
the easiest way to solve it would be to seperate out the cards a bit more

In fact, every card has 2 obects: one for the front texture and one for the back texture. So I can't seperate them out, otherwise the playing cards will get thicker... I don't really want to lower the realism by this.
So scaling everything might be the best way to do this. I'll beter do it now coz when my program gets larger it will be more dificult to do it.

freak
22
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 22nd Jan 2003 14:23
I just tried to scale it all, but it was expectable: because I scall everything down, those surfaces also come closer to eachother...
I don't see a solution to this.. maybe increasing the polygon count of the cards might solve this problem?
It would be easier to find the solution if I should know how those z-buffering works, if it was possible to see that script... I wonder if I should see the scripts behind the darkbasic commands if I use a basic decompiler on an exe file compiled in DB...

Hubdule
22
Years of Service
User Offline
Joined: 3rd Sep 2002
Location: Gundelsheim
Posted: 22nd Jan 2003 14:27
Write:

SET CAMERA RANGE 20,10000 or increase the first value ... should kill this effect ...

freak
22
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 22nd Jan 2003 14:35
increasing the front value does work, but increasing the back value has the opposite effect... it doesn't help to increase the back value

anyway, it works, u solved my problems... I'll add you to my list of people I'll mention in the credits

Hubdule
22
Years of Service
User Offline
Joined: 3rd Sep 2002
Location: Gundelsheim
Posted: 22nd Jan 2003 14:49
thx

Shadow Robert
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 22nd Jan 2003 21:35
hehee... agree with doomer, is nice to see a project that isn't going for the complex things first

this is one of those realistic projects - if you haven't already - turn off AutoCam
might seem strange but AutoCam adopts the first objects scale, this also has some knock on effects for the ZBuffer

incase it does come back heres a simpler solution ... get a modelled hand to hold up the cards a little distance infront - hehee lets see the ZBuffer try to see through that

Anata aru kowagaru no watashi!
freak
22
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 23rd Jan 2003 02:50
using autocam doesn't work in this case, as I set the camera field of view manually... anyway thanks for the hint, I'm learning every day new things about DB

this is my first serious project I guess, I hope I'll be able to finish it... It's just the beginning and I guess I have already more than 250 hrs spent at it.

Login to post a reply

Server time is: 2025-05-14 13:50:59
Your offset time is: 2025-05-14 13:50:59