How random is randomize ?

Page 1/3
| 2 | 3

By edoz

Prophet (2465)

edoz's picture

13-08-2010, 13:28

I was wondering how basic randomize works.. i mean, how the hell a computer can give something like random numbers.. because it's just a machine .. are there games that used random to activate a moster or an enemy ? .. the most games i know on the MSX the mosters are displaying always at the same time during the gameplay...

Maybe a stupid question .. but last night I was thinking about this ..

Login or register to post comments

By Hrothgar

Champion (479)

Hrothgar's picture

13-08-2010, 13:56

It can't be truly random.

When coding crappy Basic programs with Line instructions from random X to Y points with random colours, you're bound to see certain patterns appearing on screen.

Then again, these patterns may be random as well, after all you never know what random really is.

https://mywebspace.wisc.edu/lnmaurer/web/rng_stuff/Dilbert0001.jpg

By wolf_

Ambassador_ (10088)

wolf_'s picture

13-08-2010, 14:36

Computers can't generate true random values afaik. What they can do is generate patterns that appear random to us humans. The only thing to prevent returning random patterns is by seeding them according to unique situations, like date+time.

Depending on the weight of each entry in an array of random values, I think humans can't produce random values either, and since computers are just following our orders, computers can't come up with random values. I think random values for practical usage (noise sound, starfields, landscape generators, texture generators etc.), should be evenly spread across its range. Has anyone noticed that sci-fi books/movies rarely use years ending on 0 in their stories? Never 2030, always 2029, 2031, 2027, 2038 etc., just never round numbers. That's what I mean with humans not being able to produce evenly spread practical random values.. they always have emotional or creative preferences for certain numbers.

By Hrothgar

Champion (479)

Hrothgar's picture

13-08-2010, 15:31

You are right Wolf, I'm noticing the same in supermarkets as you do with SF stories.

Does anybody know how MSX randomize does work then, on a technical level? And what the best basic trick is to get numbers as random as possible?

By wolf_

Ambassador_ (10088)

wolf_'s picture

13-08-2010, 15:35

What you need is a seed based on time and date, that way it'll be different than before.

By edoz

Prophet (2465)

edoz's picture

13-08-2010, 16:13

.. like my computer can't choose. Tongue we humans can't choose Wink
There is an website .. www.random.org they claims there are using an atmospheric noise to generate random numbers.... so the question is .. what is random ;)

Maybe is it possible to forecast randomize ;)

By wolf_

Ambassador_ (10088)

wolf_'s picture

13-08-2010, 17:38

But the atmosphere is just a whole complex system o' wind, temperature and other physics. Not exactly random, just too much for most humans to grasp. Just like waterdrops in a waterfall may seem random, but their position can in theory be predicted. Makes you wonder whether real random values exist in the first place..

By Sd-Snatcher

Hero (582)

Sd-Snatcher's picture

13-08-2010, 17:43

The usual way is get the time value when the player press "start":

1010 seed=time

This is the time between swtch on the MSX and the player press "start"

then use this seed with rnd

1230 number=rnd(seed)

By flyguille

Prophet (3031)

flyguille's picture

13-08-2010, 21:58

The usual way is get the time value when the player press "start":

1010 seed=time

This is the time between swtch on the MSX and the player press "start"

then use this seed with rnd

1230 number=rnd(seed)

and after that...

a simple

seed = seed xor -1 xor (stick(player) or strig(player))

(for seed being integer value) and in the gameplay

is enought to change the seed, in impredectible way in a gameplay

making it impossible to repeat the same.

By NYYRIKKI

Enlighted (6016)

NYYRIKKI's picture

14-08-2010, 07:48

@Sd-Snatcher, flyguille: The seed does not work if it is positive number... Any positive number will give same result.

In MSX and SVI computers random numbers are calculated by using followwing algorithm :

NEW = FRC(21132486540519 * OLD + 0.14389820420821)

Because it is quite a hard to understand it like this, I wrote a example
program in BASIC to simulate RND function :

10 ' Here we have to split these numbers, elseway BASIC is
20 ' going to lose some important desimals :
30 '
40 M1= 21132480000000#:  A1= .1438982#
50        M2= 6540519#:            A2=4.20821E-09
60 '
70 R=RND(-TIME) ' Here we give a new seed for RND function. Seed is allways
80 '              reseted, when we start runnig a BASIC program.
90 '
100 CLS
110 PRINT "If you are going to use positive numbers for RND(X) funtion,"
120 PRINT "then here is next 10 values, that you are going to get :"
130 PRINT STRING$(65,"-")
140 '
150 FOR I = 0 TO 9
160 '
170 L1 = 1E-07*INT(R*10000000!)
180 L2 = R-L1
190 HE = 10000000!*(M2*L2+A2)
200 H1 = (M1*L2)-INT(M1*L2)
210 H2 = (M2*L1)-INT(M2*L1)
220 H3 = H1 + H2 + A1 + 1E-07 * INT(HE)
230 H4 = H3 - INT(H3)
240 H5 = 1E-07*(HE - INT(HE))
250 R  = H4 + H5
260 PRINT I;"|";R
270 '
280 NEXT I

By bore

Master (161)

bore's picture

14-08-2010, 11:45

I have never seen an application where you want a true random number. Almost always you are looking for a function that creates an approximatly equal distribution of the result but that is hard for humans to predict.

http://members.multimania.co.uk/leeedavison/z80/prng/index.html has a nice funtion that steps through all values between 1 and 255 in a semi-random order. It's only 8 z80 instructions so it shouldn't be to hard to get your head around.

Page 1/3
| 2 | 3