Jump to content
Mynock

BIS_fnc_selectRandom picks same one every time. Why?

Recommended Posts

I have 6 game logics placed in my mission. I want to randomly select one of these using BIS_fnc_selectRandom. I have put the names of all of the game logics into an array for the function to select from, yet it always selects logic5 no matter what. I've tested the mission 20 times now and it always picks logic5 for the location of the item I want placed there. The following is the snippet from the script, I want to use BIS_fnc_selectRandom to avoid having to write 6 if/then statements with a random number to pick a random location. What am I doing wrong?

 

_loc = [logic1, logic2, logic3, logic4, logic5, logic6] call BIS_fnc_selectRandom;
myObject setPos (getPos _loc);

 

As you can see, I have all 6 logics in the array, all of which are named. I have double checked everything, yet 20 times in a row it has selected logic5, that's too convenient and the chances of that happening are slim to none, so something is wrong. I'm not receiving any script errors.

Share this post


Link to post
Share on other sites

Hm, I don't see anything wrong with your code, so it's more than likely that it really is randomly picking logic5. I recommend you move to the scripting command version of that function, that may/may not change anything, but better nonetheless.

 

_loc = selectRandom [logic1, logic2, logic3, logic4, logic5, logic6];
myObject setPos (getPos _loc);

 

Share this post


Link to post
Share on other sites
Guest

Also check if not:

 

logic1 == logic2 == logic3 == logic4 == logic5 == logic6

 

But i had the feeling that the random in BIS_fnc_selectRandom sometimes have its preferences.

Share this post


Link to post
Share on other sites

It probably stuck because got a bit rusty as no one is using it in favour of the engine solution. Nothing WD40 cannot fix. Spray generously onto moving parts and wait a few minutes before calling it again.

Share this post


Link to post
Share on other sites
2 hours ago, killzone_kid said:

It probably stuck because got a bit rusty as no one is using it in favour of the engine solution. Nothing WD40 cannot fix. Spray generally onto moving parts and wait a few minutes before calling it again.

lol :)

Maybe someone can update the BIS_fnc_selectRandom so it uses the engine solution. Should be an easy one...

Share this post


Link to post
Share on other sites
24 minutes ago, engima said:

lol :)

Maybe someone can update the BIS_fnc_selectRandom so it uses the engine solution. Should be an easy one...

So easy in fact that it has been using the engine command for ages already. :)

Share this post


Link to post
Share on other sites

Ok, Mynock. Have you tried to selectRandom something else?

Share this post


Link to post
Share on other sites

My math is a bit dusty but isn't 1 out of 6 a 15% chance?

So not that unlikely to get it a few times in a row.
 

[["logic1",1638],["logic3",1634],["logic2",1651],["logic5",1721],["logic6",1708],["logic4",1648]]
//0.0056 ms using BIS_fnc_selectRandom


[["logic4",1636],["logic6",1729],["logic2",1658],["logic1",1623],["logic5",1621],["logic3",1733]]
//0.0013 ms using selectRandom array

Numbers add up, performance doesn't due to the nature of call (hue hue).

Use selectRandom.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

I've seen the same. fnc_selectRandom is statistically as random as selectRandom but demonstrably slower

Share this post


Link to post
Share on other sites

This is BIS_fnc_selectRandom in functionsviewer:

/************************************************************
	Random Select
	Author: Andrew Barron, rewritten by Warka, optimized by Karel Moricky, optimised by Killzone_Kid

Parameters: array

This returns a randomly selected element from the passed array.

Example: [1,2,3] call BIS_fnc_selectRandom
Returns: 1, 2, or 3
************************************************************/

/// --- validate general input
#include "..\paramsCheck.inc"
paramsCheck(_this,isEqualType,[])

selectRandom _this

KK has already changed it.

Share this post


Link to post
Share on other sites

I'll give selectRandom a try, thanks for confirming I'm an idiot for not knowing there's some sort of difference between the two.

Share this post


Link to post
Share on other sites
Guest

I trow a coin 20 times, those are the results in order of trow:

 

face,

face,

face,

face,

face,

face,

face,

face,

face,

face,

face,

counter_face,

counter_face,

counter_face,

counter_face,

counter_face,

counter_face,

counter_face,

counter_face,

counter_face

 

Near 50% for each side, but this is not random.

 

I say more about random command that i believe is used in BIS_fnc_selectRandom = {_this select floor random count _this}.

 

For loot for example, a kind of building will have loot if random 1 < 0.6 is true for it, ok, so i enter in 10 of those buildings and find no look, ok its possible, so this happens again and again more than you expect.

For a building you have random 1 < 0.1, you enter in 10 buildings of that in a city and 6 have loot.

 

But its ok, its just a feeling, i dont know when i will have the time to kill the ghosts, i have i girl friend now :soldier:

Share this post


Link to post
Share on other sites

I have no clue what you're getting at with that, unless you're just confirming that yes there is a chance a bunch of random things could all be the same. I'm not looking to make a loot script, but thanks for the information.

Share this post


Link to post
Share on other sites
Guest
1 hour ago, Mynock said:

I'll give selectRandom a try, thanks for confirming I'm an idiot for not knowing there's some sort of difference between the two.

 

I'm saying you is not an idiot. But i forgot i'm one :don12:

Share this post


Link to post
Share on other sites

I was dumb for assuming BIS_fnc_selectRandom was the only solution because I see a lot of people using it for randomly generated missions, so I figured that was what I should use also instead of investigating further to see if there were other, better things to use. Now I'm willing to bet during mission initialization that bit of code is hanging up causing it to always select the same spot because apparently that's a really slow command, therefore I could have solved my own problem had I been smart enough to investigate other scripting commands, but instead I'm an idiot and assumed that one would work because it works for other people.

Share this post


Link to post
Share on other sites
9 minutes ago, Mynock said:

investigate other scripting commands

 

Well there's the glorious selectRandomWeighted incoming in 1.73, which works out great if you don't want to totally randomize stuff but give it a nudge in a certain direction.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites
15 minutes ago, Mynock said:

I was dumb for assuming BIS_fnc_selectRandom was the only solution because I see a lot of people using it for randomly generated missions

A lot of the threads that have helped people setup those randomly generated missions where created well before the command solution to BIS_fnc_selectRandom existed. A solution is a solution though, just like in early math classes where they teach you the long way and force you to master the concept before showing you a shortcut that takes all of 2 seconds. You just learned of the shortcut, no need to go at yourself for it :thumb:.

Share this post


Link to post
Share on other sites

When/where do you run this code?

If you're sure you have correctly name your logics, I'm sure you are, just test something spawning:

0= [] spawn {

  _logics = [logic1, logic2, logic3, logic4, logic5, logic6];

  _loc = selectRandom _logics;

   myObject setPos (getPos _loc);

};

Or KK solution, even better.

Share this post


Link to post
Share on other sites
13 minutes ago, killzone_kid said:

If you want to setPos of an object, use setVehiclePosition with array of markers
 

myObject setVehiclePosition [pos1, ["mrkpos2", "mrkpos3", "mrkpos3"....], 0, "NONE"];

https://community.bistudio.com/wiki/setVehiclePosition

no need to reinvent the wheel

 

I'm not trying to reinvent the wheel, I'm simply ignorant to the thousands of ways to do anything in this game. I'm also not sure if this will work for me seeing as not every location is on the ground, some are on second or third floors of buildings, which is why I prefer to use logics so I can place them in the 3d editor more easily at the appropriate height vs a marker, but if this is still the wrong way to do it then I will change it to markers.

 

selectRandom is working better, still certainly prefers logic5 for some reason, but at least now it's picking other locations within a few tries vs 20 all at the same location. Very strange why the fnc doesn't work correctly for some unknown reason to me.

Share this post


Link to post
Share on other sites
14 minutes ago, Mynock said:

 

I'm not trying to reinvent the wheel, I'm simply ignorant to the thousands of ways to do anything in this game. I'm also not sure if this will work for me seeing as not every location is on the ground, some are on second or third floors of buildings, which is why I prefer to use logics so I can place them in the 3d editor more easily at the appropriate height vs a marker, but if this is still the wrong way to do it then I will change it to markers.

 

If you have just 5 positions, take time to place the player in editor preview, note position, direction and even stance in debug console (watch lines for example), then hard copy the figures in due arrays/scripts. No need to have logics for that.

Share this post


Link to post
Share on other sites

I could, but logics are significantly faster for me. But if that's the wrong way to do it then I need to consider redoing this mission from scratch because I'm sure I did a lot of others things the wrong way then too.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×