Novahq.net Forum

Novahq.net Forum (https://novahq.net/forum/index.php)
-   Delta Force (https://novahq.net/forum/forumdisplay.php?f=101)
-   -   [DFX2] Is RaNDom truly random? (https://novahq.net/forum/showthread.php?t=47896)

Guest001 04-23-2016 07:24 AM

Is RaNDom truly random?
 
Random functions don't seem to be truly random.

After trying DORND without success I've resorted to the code below in various forms and with mixed results.

Code:

if never then
set v1,0
endif

if past 1 and elapse 1 then
    consol# "v1,",v1
    consol# "v1,",v1
    consol# "v1,",v1
endif

if eq v4,1 and never then
    set v1,0
endif

if random 3 and ne rnd, 2 and ne rnd, 3 then
    set v1,1
else if ne rnd, 1 and ne rnd, 3
    set v1,2
else if ne rnd, 1 and ne rnd, 2
    set v1,3
endif
endif
endif

if eq v1,1 and ne v1,2 and ne v1,3 and never then
    set v4,1
    SSNtoWP 4,1
endif

if eq v1,2 and ne v1,1 and ne v1,3 and never then
    set v4,1
    SSNtoWP 4,2
endif

if eq v1,3 and ne v1,1 and ne v1,2 and never then
    set v4,1
    SSNtoWP 4,3
endif

Still doesn't work.

Baldo_the_Don 04-24-2016 12:20 AM

You don't need to set v1 to 0 at the start 'cause without instructions to change a variable, the game defaults all variables to 0.

I'm not sure why you want v1 displayed in all three console lines each second.

This is how I think randomness works in DBHFD: "if random 3" tells the game to set up a loop of values between 1 and 3 (but not 0) changing "randomly" every second, and to trigger this event when the value 1 occurs.

If "random 3" equals 1, then it cannot also equal 2 or 3 at the same time, so excluding those in the "if" is extraneous, in my opinion.

I think the last three events would work more reliably nested in an "if ontick X then" event. That would also negate the need for v4 to shut v1 off.

I agree with you that "random" is not true randomness in NovaLogic games. I don't think true randomness is possible for a computer to create, it can only simulate it as closely as possible to a point that humans can't really tell it's a pattern. My experience with DFBHD is that there is a simple randomish pattern that the game uses to set up random loops, and if you want something more truly random, you have to fiddle with it.

So if you set up a simple "random 3" and edit the redirects to nest in an "if ontick", then the truer randomness will hinge on how you choose the tick that the redirect triggers on. I'm pretty sure the same "random 3" value will always happen at the same tick in game, but I haven't really tested that well.

Guest001 04-24-2016 03:24 AM

Quote:

Originally Posted by Baldo_the_Don (Post 385434)
You don't need to set v1 to 0 at the start 'cause without instructions to change a variable, the game defaults all variables to 0.

I'm not sure why you want v1 displayed in all three console lines each second.

This is how I think randomness works in DBHFD: "if random 3" tells the game to set up a loop of values between 1 and 3 (but not 0) changing "randomly" every second, and to trigger this event when the value 1 occurs.

If "random 3" equals 1, then it cannot also equal 2 or 3 at the same time, so excluding those in the "if" is extraneous, in my opinion.

I think the last three events would work more reliably nested in an "if ontick X then" event. That would also negate the need for v4 to shut v1 off.

I agree with you that "random" is not true randomness in NovaLogic games. I don't think true randomness is possible for a computer to create, it can only simulate it as closely as possible to a point that humans can't really tell it's a pattern. My experience with DFBHD is that there is a simple randomish pattern that the game uses to set up random loops, and if you want something more truly random, you have to fiddle with it.

So if you set up a simple "random 3" and edit the redirects to nest in an "if ontick", then the truer randomness will hinge on how you choose the tick that the redirect triggers on. I'm pretty sure the same "random 3" value will always happen at the same tick in game, but I haven't really tested that well.

Thanks Baldo :)


set v1,0 sets the state relationship in events.
eq rnd, 1 selects the random value EDIT(using ne rnd, 2 etc helped exclude read errors when incrementing)

Found using v1 v2 v3 etc complicated things

For example:

If nothing else uses v1 then you wouldn't need to set it (init) at all because you set the variable when you call (declare) it locally with, if trigger then set v1,1

Baldo_the_Don 04-24-2016 04:41 AM

I just tried this:

Code:

if random 3 then set v1 1 else
if eq rnd 2 then set v1 2 else
if eq rnd 3 then set v1 3
endif
endif
endif

if ontick 3 then
if eq v1 1 then ssntowp 4 1 endif
if eq v1 2 then ssntowp 4 2 endif
if eq v1 3 then ssntowp 4 3 endif
endif

text# "Random =" rnd

SSN 4 redirects to WP 2 on tick 2, WP 1 on tick 3, and WP 3 on tick 4. This remains consistent over multiple restarts.

For fun, I changed "if random 3" to 6. The text displayed 5 more rarely than I expected. Did not note which WPs got the redirect, though.

I'm convinced truer randomness depends on when and how the redirect is triggered.



Edit: I'm aware that leaving the "text#" action untagged is bad form, but I think it's acceptable for testing purposes.

Guest001 04-24-2016 05:23 AM

; 1 "select 1 or 3 randomly" Does this example from DFX2 documentation mean you can't have more than 2 factors? Or is it a typo?
;example select 1 or 3 randomly

if random 3 then
text "1"
else if eq(rnd, 2)
text "2"
else if eq(rnd, 3)
text "3"
endif
endif
endif

;2 Here with DORND and the auto player variable it'll just assign the values in a logical order from top to bottom - no random at all.

if past(3) and not ssndead(10000) and never() then
DORND
ploop text ("auto, 10") end
NEXT
ploop text ("auto, 20") end
NEXT
ploop text ("auto, 30") end
NEXT
ploop text ("auto, 40") end
NEXT
ploop text ("auto, 50") end
ENDDO

Guest001 04-24-2016 06:04 AM

Quote:

Originally Posted by Baldo_the_Don (Post 385436)
I just tried this:

Code:

if random 3 then set v1 1 else
if eq rnd 2 then set v1 2 else
if eq rnd 3 then set v1 3
endif
endif
endif

if ontick 3 then
if eq v1 1 then ssntowp 4 1 endif
if eq v1 2 then ssntowp 4 2 endif
if eq v1 3 then ssntowp 4 3 endif
endif

text# "Random =" rnd

This remains consistent over multiple restarts.

SRY didn't see this...
Quote:

This remains consistent over multiple restarts.
That's exactly what I mean and so it's not quite what I want.

It requires a different start each time but thanks anyway:gj:

Guest001 04-24-2016 06:32 AM

So it seems to look as though randoms are tied to the same clock or something like that.

They'll go off simultaneously or in in the same order every time.

They also seem to "jump the fence" or over-run, not stopping and you can't seem to "capture" them like other events either.

Good for triggering lightning etc.. which also has a few bugs by the way.

Baldo_the_Don 04-24-2016 07:56 AM

The .wac I inserted above was tested in DFBHD. I don't own nor have any experience with DFX2, so I'm not sure what "ploop" means (player operation?), but it makes my inner 7-year-old giggle.

I think "select 1 or 3 randomly" was supposed to be "select 1, 2 or 3 randomly," 'cause that's what that event nest will do. That bit is also in the KYLE.WAC for DFBHD as well.

Finally, just to spout completely unqualified, inexperienced conjecture, I'm gonna guess that if you changed the DORND script by making the NEXT operations to OR operations, it might work differently, or maybe crash the game, possibly start wildfires on America's west coast. I have no idea.

Guest001 04-24-2016 11:14 AM

It just doesn't seem to work in DFBHD either Baldo - even with raw script like this.

Code:

if ontick 1 and never then
ssn2ssn 1 4
ssn2ssn 2 5
ssn2ssn 3 6
endif

if ticks 2 and random 4 and never then
v1 =0 else if rnd ==2 then
v1 =1 else if rnd ==3 then
v1 =2 else if rnd ==4 then
v1 =3
endif
endif
endif
endif

if past 9 and ticks 9 and random 5 and never then
if never and v1 ==1 then ssntowp 4 1 endif
if never and v1 ==2 then ssntowp 4 2 endif
if never and v1 ==3 then ssntowp 4 3 endif
endif

text# "v1 =" v1


Guest001 04-24-2016 01:46 PM

Found this post in an unrelated forum though the subject matter had nothing to do with this particular problem, it could be a possible reason for the issues with this.

BTW
This is just as difficult as counting player deaths and then apply variables to them.

Try it... :)

Quote:

"From your comment that you saw the first number is still the same. This is caused by the implementation of random generator in some platforms.

The solution is to pop some random numbers before using them for real"
I think the op means to use some (random results) up first

Guest001 04-24-2016 03:30 PM

Getting closer with this.

Code:

if ontick(1) and never() then
ssn2ssn(1,4)
ssn2ssn(2,5)
ssn2ssn(3,6)
endif

if random(4) and never then
else
if (rnd == (2)) and (rnd != (1)) and never then (v1 = (1))
else
if (rnd == (3)) and never then (v1 = (2))
else
if (rnd == (4)) and never then (v1 = (3))
endif
endif
endif
endif

if (rnd == 4)) then
inc(v10)
endif

if eq(v10,4) and never then
random()
random()
random()
else
if never and v1 ==1 and random(2) then ssntowp 4 1 endif
else
if never and v1 ==2 and random(2) then ssntowp 5 2 endif
else
if never and v1 ==3 and random(2) then ssntowp 6 3 endif
endif
endif
endif
endif

consol# "v1 =" v1
text# "v10 Response" v10


Guest001 04-24-2016 03:54 PM

And again almost but not a true random - looks like it's just not possible with this method.

Need to find a master script - where they declare the global vars - just hope it's somewhere in one of the PFFs not inside the exe.

Code:

if ontick(1) and never() then
ssn2ssn(1,4)
ssn2ssn(2,5)
ssn2ssn(3,6)
endif

if random(4) then
random()
random()
random()
else
if (rnd == (2)) and (rnd != (1)) and never then (v1 = (1))
else
if (rnd == (3)) and never then (v1 = (2))
else
if (rnd == (4)) and never then (v1 = (3))
endif
endif
endif
endif


if never and v1 ==1 then ssntowp 4 1
endif
if never and v1 ==2 then ssntowp 5 2
endif
if never and v1 ==3 then ssntowp 6 3
endif


consol# "v1 =" v1
text# "rnd Response" rnd


Guest001 04-25-2016 03:54 AM

Not giving up... yet.

Another clue.

The script below is in C# and I'm thinking - suspecting - guessing that NL used C# to build their game engine so there may be a way to create a math random with WAC script using C# as a basis... :thud:

REF: http://stackoverflow.com/questions/2...t-number-in-c]
Quote:

Originally Posted by Stack Overflow


The Random class is used to create random numbers, Pseudo-random that is of course.

Example:

Code:

Random rnd = new Random();
int month = rnd.Next(1, 13); // creates a number between 1 and 12
int dice = rnd.Next(1, 7);  // creates a number between 1 and 6
int card = rnd.Next(52);    // creates a number between 0 and 51

If you are going to create more than one random number, you should keep the Random instance and reuse it. If you create new instances too close in time, they will produce the same series of random numbers as the random generator is seeded from the system clock.


Guest001 04-26-2016 12:54 PM

True Random Number Services - on the internet abound - if only it was just numbers for a X-Lotto form that we really needed but this is a little more complex.

Random numbers would be fine if we could work out the script to generate them and then insert them into a variable.

I seem to recall something about that so I'll probably end up going back to the test map but it's been a hard slog.

Any ideas even remotely along these lines would be appreciated so please feel welcome to put your idea(s) here.

In recapping on previous issues even jumping in the helo at different times or going through triggers isn't working.

I expected the scripts in many previous attempts to work.

The advice given here was sound with many thanks to Baldo and Chopper for their solutions which should have worked in the given scenario.

It's puzzling and forces a rather distasteful series of questions and answers to mind.

If that's the way it is, then the answer is nada but if it's a bug?

Is there in fact, some sort of curly workaround for it?

Guest001 04-26-2016 01:17 PM

Back again...
COUNTING TICKS 1/10 sec
Could we get the variable to select from a random range?
Further...
Can we apply a number range between 0 and 1 exclusive then add 1 to keep it over zero?

newrandom# = 1 * (0.1,0.9) +1

Quote:

Originally Posted by stompem (Post 385453)

More Info:

Example
Code:

random(100)
The first call to Set Random passes in the value 100. This is a seed that controls the random numbers that are generated.

If we continued to call the Random and stored all the values we'd get a sequence of random numbers.

Though if we repeat the process the sequence will be the same.

The reason is the seed remains 100 and the clock starts a zero each time, so the same sequence of random numbers will be generated each time.

If we were to some how set this seed to the current OS time on startup or delay the clock somehow, it may seed a different sequence of numbers each time the function is called at game start.


Oscarmike247 02-07-2018 09:22 AM

I have expiremented with random operations once before and it does work but not very well. If im not mistaken, if "random (#)" means the event will be true 1 out of # times.

If you want to have a random action from a single trigger use "dornd" .

I expiremented with this before. I wanted a respawning AI to take a random path of 3 different waypoints each time it respawned.

If ssnnearssn ( 1, 2, 2) and ssnalive (1) and elapse(3) then
Dornd
ssntoWP (1, 1)
next
ssntoWP (1, 2)
next
ssntoWP (1, 3)
Enddo
Endif

So if SSN 1 is alive and within 2 meters of spawnpoint: SSN 2 ( used a marker) then randomly trigger one of the following actions. Test every 3 seconds.

This worked for me, the AI would take one of the 3 paths at random, BUT sometimes, it would get stuck in a loop where for 10 spawns straight it would take the same path but after the 10 or so cycles it would again start taking a different path.

Guest001 02-11-2018 09:40 PM

Hi thanks for helping but I didn't give up, eventually I found a way and published the map.

Here's the map if you're interested.

Human vs AI - Special Forces
http://novahq.net/maps.php?ID=10470


Here's the code for detecting player deaths - so simple in the end.

Code:

;Count Player Deaths

if never() then
set(v1,0) // Triggers once then resets
set(v2,0) // Count 1 adds
set(v3,0) // Count 2 Subtracts
endif

if not ssnalive(player) then
set(v1,1)
endif

if eq(v1,1) then
set(v1,0)
endif
; Use chain to trigger once each time the variable flips - link will keep counting
if chain(1) then
add(v2,1)
sub(v3,1)
endif

As you probably know you can pick the random using relational operators.

Random=3 or random(3) is more or less setting the variable to 3

Random==3 or eq means the random value is equivalent to 3

Though I think "=" and "==" are inter-operable because they are both true.

gt > (greater-than)

lt < (less-than)

neq != (not equal to)

eq == (equivalent to)

etc. etc.

NOTE: The following eq example uses parentheses.

Code:

if never() and random(10) then
        if eq(v1,0) and eq(rnd, 3) then
                set(v14,1)
        end
endif
//
if eq(v14,1) then
        ammo2tgt AMMO_60MM_MORTAR(1)
 dec(v14)
endif


Oscarmike247 02-12-2018 04:52 PM

1 Attachment(s)
Quote:

Originally Posted by stompem (Post 388882)
Hi thanks for helping but I didn't give up, eventually I found a way and published the map.

Here's the map if you're interested.

Human vs AI - Special Forces
http://novahq.net/maps.php?ID=10470


Here's the code for detecting player deaths - so simple in the end.

Code:

;Count Player Deaths

if never() then
set(v1,0) // Triggers once then resets
set(v2,0) // Count 1 adds
set(v3,0) // Count 2 Subtracts
endif

if not ssnalive(player) then
set(v1,1)
endif

if eq(v1,1) then
set(v1,0)
endif
; Use chain to trigger once each time the variable flips - link will keep counting
if chain(1) then
add(v2,1)
sub(v3,1)
endif

As you probably know you can pick the random using relational operators.

Random=3 or random(3) is more or less setting the variable to 3

Random==3 or eq means the random value is equivalent to 3

Though I think "=" and "==" are inter-operable because they are both true.

gt > (greater-than)

lt < (less-than)

neq != (not equal to)

eq == (equivalent to)

etc. etc.

NOTE: The following eq example uses parentheses.

Code:

if never() and random(10) then
        if eq(v1,0) and eq(rnd, 3) then
                set(v14,1)
        end
endif
//
if eq(v14,1) then
        ammo2tgt AMMO_60MM_MORTAR(1)
 dec(v14)
endif


played your map and thoroughly enjoyed it. I commented in the map posting.

I beat all 10 levels first try with no deaths though. :p Do I get a special prize?

Guest001 02-14-2018 08:51 PM

Quote:

Originally Posted by Oscarmike247 (Post 388884)
played your map and thoroughly enjoyed it. I commented in the map posting.

I beat all 10 levels first try with no deaths though. :p Do I get a special prize?

MMMM, I thought it was originally too hard for the average player, so I toned it down to where it was just a bit of fun.

The .mis file is in the download so perhaps you could have a go at improving it, I don't mind.


All times are GMT -5. The time now is 01:41 AM.

Powered by vBulletin®