Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
random num generation
#1
im trying to use a random number function in my rpg battle system but something was goin wrong... i discovered that it was only generating once and saving as that random number, how do i make it generate randomly each time?? Cry
-p
Reply
#2
RTFM MAN!!!

R.T.F.M!!

Search for RANDOM inside the QB help system..

it's ......

RANDOMIZE TIMER
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#3
do you think id b asking for help if the randomize timer worked! thats the whole point :-( its not working for me
-p
Reply
#4
Hmm...after you do the RANDOMIZE TIMER, are you then invoking RND with a negative number? If so, then the RANDOMIZE TIMER effect will be ignored.

- Dav
Reply
#5
Thanks!!! u helped loads dave!!!
i had sumhow got my random numbers to equal zero so it was sticking on one value!!

CHEERS loads!
:bounce:
-p
Reply
#6
No Prob...

Here's a small bit of an article by Microsoft about using RANDOMIZE and RND which gives a little more info than the online help has...

..................................


The first invocation of the RANDOMIZE statement determines a given set of random numbers returned from successive calls to the RND function. Not invoking the RANDOMIZE statement in a program is equivalent to invoking RANDOMIZE 0 before invoking RND. Note that a second (or subsequent) RANDOMIZE x statement does not restart the number sequence from the beginning of the set for a given x, but it randomly changes (reseeds) the sequence from what it would have been from that point on. This behavior is by design. Example 2 below illustrates this in detail.

If you want to return the same sequence of random numbers several times within a given program run, you can invoke the RND function with the exact same negative number argument followed by a sequence of RND invocations with a positive argument or no argument. Invoking RND with a negative argument eliminates the effect of a previous RANDOMIZE statement. Please see Example 1 below for further illustration.


Example 1
---------

(This example of invoking RND once with a negative argument always returns the same sequence of random numbers for subsequent invocations of RND.)

Code:
CLS
RANDOMIZE TIMER   ' Ignored unless you remove RND(-1) below.
FOR j = 1 TO 2
' Passing a negative value to the RND function supersedes the effect
' of the previous RANDOMIZE TIMER statement:
PRINT RND(-1)   ' Remove this line for a different sequence on every
                 ' loop iteration. Otherwise, each j loop iteration
                 ' (and separate program run) returns the same
                 ' three-number sequence for the inner i loop.
FOR i = 1 TO 3
    PRINT RND
NEXT I
PRINT
NEXT J

Example 2
---------
Code:
FOR k = 1 TO 5
  PRINT RND
NEXT k

Below is the default random number set output from the above program, when run with QB.EXE version 4.0 on an IBM PC. The following sequence of random numbers varies with different versions of Microsoft QuickBasic and Basic Compilers:

.7107346
.99058
.8523988
.3503776
4.363585E-02

The following code shows the effect of RANDOMIZE 0 at start-up:

Code:
PRINT  "Set the seed to zero at startup"
RANDOMIZE 0
FOR k = 1 TO 5
  PRINT RND
NEXT k
PRINT "Again, reset the seed to zero"
RANDOMIZE 0
FOR k = 1 TO 5
  PRINT RND
NEXT k

The above program has the following output:

Set the seed to zero at startup
.7107346
.99058
.8523988
.3503776
4.363585E-02
Again, reset the seed to zero
.7987763
.6497337
.5426014
.9642789
8.590406E-02

Note: The second invocation of RANDOMIZE 0 does not restart the sequence from the beginning. This is by design. If you remove the second RANDOMIZE 0 statement and run the program again, the sixth through tenth numbers are different than above. This shows that multiple RANDOMIZE statements reseed the sequence (and change the random number set displayed), but they do not restart the sequence from the beginning.

...............................................
Reply
#7
Oh. I didn't know that.

Anyways, M$'s random number sequences are a big load of hokey.

The RND sequence has a very clear pattern to it.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#8
is going to have some pattern to it if you look hard enough. (But no, I wouldn't have expected the Redmond Mafia to have even tried to do as good a job as they could have.)
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#9
sw? what is sw?
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#10
clue: it's the opposite of hw Tongue
In a world without walls and doors, who needs Windows and Gates?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)