tpw 2315 Posted October 7, 2010 Gday all I'm working on a little script that just has my squad members saying random lines of dialog using sidechat. I've set up an array of several hundred pithy sayings in _dialog, and use it thusly: _dcount = count _dialog; while {alive player} do { // The squad (not including player) _squad = []; {if (!isplayer _x) then {_squad = _squad + [_x]}} foreach units (group player); _scount = count _squad; // Get a random squaddie to say a random line _speaker = _squad select (floor random _scount); _line = _dialog select (floor random _dcount); if ((behaviour _speaker == "SAFE") or (behaviour _speaker == "AWARE") or (behaviour _speaker == "CARELESS")) then {_speaker sidechat _line}; sleep (30 + random 60); } Now this actually works very well, in that a random squad member will say something every 30-90 seconds. However they just keep saying the same 6-10 lines out of the several hundred to choose from. Is there any way to reseed random or do something to make it more random? Share this post Link to post Share on other sites
Muzzleflash 111 Posted October 7, 2010 As far as I know you cannot reseed the generator. It does get random with more iterations, however in small runs it does seem to repeat some number many times. I tested using this script: private ["_number","_old","_text","_iterations","_max_plus_plus","_data"]; _iterations = 10000; _max_plus_plus = 10; _data = []; //Initialize for "_i" from 0 to (_max_plus_plus-1) do { _data set [_i, 0]; }; //Get values for "_i" from 1 to _iterations do { _number = floor random _max_plus_plus; _old = _data select _number; _data set [_number, _old+1]; }; _text = ""; //Print em for "_i" from 0 to (_max_plus_plus-1) do { _text = _text + format ["%1 => %2\n", _i, _data select _i]; }; hint _text; With 10000 iterations and from 0 to 9 the result are distributed pretty equal. However with only 20 iterations I got 6-nines. These results suggests that the same numbers comes quite close followed by another sequence with another number. Maybe you can try generate a number much larger than needed and then use the modulo operator to limit it the to the number of dialogs entries you have, although I suspect this is the way random works already. Share this post Link to post Share on other sites
tj72 0 Posted October 7, 2010 (edited) debug it with: hintsilent format ["%1 number of sayings available",_dcount ] You could check to see if the random selection is the same as the last time and if yes then randomize again. It would be harder but better to make a list of all the used sayings so that they all eventually get used but then the list is clear after that so it starts over. You would have to make all of that. Just theorizing here but that is a thought that occured to me when I randomize things. Cool idea btw.... Edited October 7, 2010 by TJ72 took out 54 ? :P Share this post Link to post Share on other sites
callihn 10 Posted October 7, 2010 True, setting a variable to hold the last value and refusing to reuse it would probably fix your problem. Share this post Link to post Share on other sites
tpw 2315 Posted October 7, 2010 Thanks guys, great ideas. I'll definitely try forcing it to use a different number each time. Share this post Link to post Share on other sites
callihn 10 Posted October 8, 2010 (edited) Just testing myself and random does not appear to be random at all for me: 100 + round(random 5000) Returns 155 EVERYTIME. 2000 + round(random 10000) Returns 9315 EVERYTIME. 5000 + round(random 20000) Returns 22254 EVERYTIME. EDIT: Until next time that is then the numbers change but then that value returns EVERYTIME I run it again. EDIT2: Silly me, I guess that happens when you call random inside of a static array. Edited October 8, 2010 by callihn Share this post Link to post Share on other sites
bhaz 0 Posted October 8, 2010 You could code in a simple blacklist, of say the last three or four dialog lines, to make sure the same content doesn't repeat so often? If random pulls a number that's on the temporary blacklist, just make it pull another one. :) Share this post Link to post Share on other sites
nuxil 2 Posted October 8, 2010 this is a small function i used in a mission to randomizie some towns. NUX_Randomize_Array = { _array = _this; _size = count _array; _newarray = []; _newnr = []; while {(count _newnr) < _size} do { scopeName "redonr"; _nr = floor(random _size); if (_nr in _newnr) then { breakTo "redonr"; }else{ _newnr = _newnr + [_nr]; _newarray = _newarray + [_array select _nr]; }; sleep 0.01; }; _newarray }; _Citys = ["city1","city2","city3","city4","city5","city6","city7","city8","city9","city10","city11","city12","city13","city14","city15"]; _randCityArray = _Citys call NUX_Randomize_Array; what this does is randomize the array _City and stores it in _randCityArray. i guess you could do the same. with your text. _text1 = "foo"; _text2 = "bar"; _text3 = "moo"; _myarray = [_text1,_text2,_text3]; _newrandomarray = _myarray call NUX_Randomize_Array; for "_i" from 0 to (count _newrandomarray - 1) do { sleep (30 + random 60) // more code to select random uint. _line = _newrandomarray select _i; _unit_X sidechat _line }; i have not tested this and all other code than the function is pseudo code. but i hope you get the idea. Share this post Link to post Share on other sites
tpw 2315 Posted October 8, 2010 Perfect! I'll give it a try ASAP and let you know how it looks. Thanks very much nuxil. this is a small function i used in a mission to randomizie some towns. NUX_Randomize_Array = { _array = _this; _size = count _array; _newarray = []; _newnr = []; while {(count _newnr) < _size} do { scopeName "redonr"; _nr = floor(random _size); if (_nr in _newnr) then { breakTo "redonr"; }else{ _newnr = _newnr + [_nr]; _newarray = _newarray + [_array select _nr]; }; sleep 0.01; }; _newarray }; _Citys = ["city1","city2","city3","city4","city5","city6","city7","city8","city9","city10","city11","city12","city13","city14","city15"]; _randCityArray = _Citys call NUX_Randomize_Array; what this does is randomize the array _City and stores it in _randCityArray. i guess you could do the same. with your text. _text1 = "foo"; _text2 = "bar"; _text3 = "moo"; _myarray = [_text1,_text2,_text3]; _newrandomarray = _myarray call NUX_Randomize_Array; for "_i" from 0 to (count _newrandomarray - 1) do { sleep (30 + random 60) // more code to select random uint. _line = _newrandomarray select _i; _unit_X sidechat _line }; i have not tested this and all other code than the function is pseudo code. but i hope you get the idea. Share this post Link to post Share on other sites