• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Units are instructed to go to a random location, but they choose the same place over and over, but not ALWAYS.

Level 5
Joined
Mar 10, 2021
Messages
24
Occasionally they will choose a new target, but so often they will send a wave to the same place over and over.

What on earth does this? Why is it "randomly" choosing the same location so many times in a row?
  • AttackWavesAppear
    • Events
      • Game - The in-game time of day becomes Equal to 18.01
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • WaveContentsCount Less than 12
        • Then - Actions
          • Unit - Create 2 WFrontLinerWave for Player 12 (Brown) at (Center of EnemyStart <gen>) facing Default building facing degrees
          • Unit - Create 2 WBackLinerWave for Player 12 (Brown) at (Center of EnemyStart <gen>) facing Default building facing degrees
          • Unit - Create 2 WCasterWave for Player 12 (Brown) at (Center of EnemyStart <gen>) facing Default building facing degrees
        • Else - Actions
          • Set VariableSet WaveContentsCount = (WaveContentsCount - 6)
          • Set VariableSet WaveTarget = (Random unit from (Units in (Playable map area) matching (((Matching unit) is A town-hall-type unit) Equal to True)))
          • Unit - Create 1 WSiegeWave for Player 12 (Brown) at (Center of EnemyStart <gen>) facing Default building facing degrees
          • Unit Group - Pick every unit in (Random 6 units from (Units in EnemyStart <gen> owned by Player 12 (Brown))) and do (Actions)
            • Loop - Actions
              • Unit - Move (Picked unit) instantly to (Center of EnemyStageWave <gen>)
              • Unit - Order (Picked unit) to Attack-Move To (Position of WaveTarget)
          • Set VariableSet WaveContentsCount = (WaveContentsCount - 6)
          • Set VariableSet WaveTarget = (Random unit from (Units in (Playable map area) matching (((Matching unit) is A town-hall-type unit) Equal to True)))
          • Unit - Create 1 WSiegeWave for Player 12 (Brown) at (Center of EnemyStart <gen>) facing Default building facing degrees
          • Unit Group - Pick every unit in (Random 6 units from (Units in EnemyStart <gen> owned by Player 12 (Brown))) and do (Actions)
            • Loop - Actions
              • Unit - Move (Picked unit) instantly to (Center of EnemyStageWave <gen>)
              • Unit - Order (Picked unit) to Attack-Move To (Position of WaveTarget)
Is the game simply unable to handle randomness or what? It's very consistent and breaks the whole point of the map. Is it my trigger and I simply don't understand?

EDIT: I rewrote it and simply added a second condition to the pick for the WAVETARGET to ensure that it wasn't WAVETARGET and will not repeat ever.
 
Last edited:
Level 20
Joined
Aug 29, 2012
Messages
832
If you're testing your map via the editor directly, make sure this option is unticked, it will mess up with the random picks

1702255952099.png
 
Level 39
Joined
Feb 27, 2007
Messages
5,023
I think it’s important to highlight that truly random sequences of data will contain long strings of repeat results and long strings that lack a specific result. True random does not mean “every result is different” and you should not expect it to behave that way.

There is a paradox that humans tend to see such results as being distinctly anti-random, but in truth they are a very important way to distinguish that a data set was in fact produced without a bias. Human-generated data regularly fails to be truly random because we try to distribute the randomness evenly, but the universe does not do that and it plays no games.
 
Level 19
Joined
Jan 3, 2022
Messages
320
This "random" is not very random.
I wrongly assumed that function would have a bias towards zero when its final pick will be rolled from the entire group range [0, groupSize)

Lua:
#!/usr/bin/env lua

function rollUnitRnd(unitCount)
   local currentPick = 0
   for i = 1, unitCount do
      local r = math.random(1, i)
      if r == 1 then
          currentPick = i
      end
   end
   return currentPick
end

function sim(unitCount, rep)
   local results = {sum=0}
   for i = 1, unitCount do results[i] = 0 end

   for i = 1, rep do
       local res = rollUnitRnd(unitCount)
       results[res] = 1 + results[res]
   end


   for i = 1, #results do
      results.sum = results.sum + results[i]
   end

   print("unitN, count, %")
   for i = 1, #results do
      print(i, results[i], results[i] / results.sum)
   end
end

math.randomseed(os.time())
sim(5, 10000000)
-- run with
-- lua getunitrandom.lua
It wasn't this function's fault.

@ArcadeKid if you still suspect faulty random then create a simulation trigger like I did in code and run it many times when you enter a command, writing down chosen Town hall in a Leaderboard. You can differentiate THs in this test either by setting custom unit data or giving them different names.

Also your trigger produces group leaks (new groups creates and never removed) and same for Locations (like Point of...)
 
Level 5
Joined
Mar 10, 2021
Messages
24
I wrongly assumed that function would have a bias towards zero when its final pick will be rolled from the entire group range [0, groupSize)

Lua:
#!/usr/bin/env lua

function rollUnitRnd(unitCount)
   local currentPick = 0
   for i = 1, unitCount do
      local r = math.random(1, i)
      if r == 1 then
          currentPick = i
      end
   end
   return currentPick
end

function sim(unitCount, rep)
   local results = {sum=0}
   for i = 1, unitCount do results[i] = 0 end

   for i = 1, rep do
       local res = rollUnitRnd(unitCount)
       results[res] = 1 + results[res]
   end


   for i = 1, #results do
      results.sum = results.sum + results[i]
   end

   print("unitN, count, %")
   for i = 1, #results do
      print(i, results[i], results[i] / results.sum)
   end
end

math.randomseed(os.time())
sim(5, 10000000)
-- run with
-- lua getunitrandom.lua
It wasn't this function's fault.

@ArcadeKid if you still suspect faulty random then create a simulation trigger like I did in code and run it many times when you enter a command, writing down chosen Town hall in a Leaderboard. You can differentiate THs in this test either by setting custom unit data or giving them different names.

Also your trigger produces group leaks (new groups creates and never removed) and same for Locations (like Point of...)
Hello thank you for all of this, however I solved the issue more or less by adding "Picked Unit Matching(Matching Unit is NOT WaveTarget)" so now it will NEVER pick the same one twice in a row. With some other changes even in the case of the random being broken, I have not been able to notice it.
 
Level 21
Joined
Dec 3, 2020
Messages
523
@ArcadeKid , I also learnt this the practical way. So... the more random you make something, the less random it becomes.
You have to make it less random manually if you want it to appear more random. Sounds weird but it's true.
I also had this issue on 1 of my maps but it didn't really matter, but I basically spawned infernals in random points of some regions every X time and a lot of the times the infernals would spawn on the same coordinates/spots.
 
Top