Sorry in advance if this sounds condescending- since having a kid, I’ve forgotten how to explain things to adults.
It isn’t for randomization. The purpose of this code is to create a non-linear relationship between quantity smuggled and chance to be caught.
The equation you gave is pretty dense, and some unpacking would inform our analysis. The expression that caught my attention immediately was this:
this.GD.Towns[i].illegalActions[j].amount / this.GD.Towns[i].illegalActions[j].smugglingSkill
This informs us that there are actually only two variables: quantity smuggled and smuggling skill. Because it’s impossible to smuggle a mass of contraband in kg greater than your skill, this expression will only ever return a value between 0 and 1. Zero would be no illegal materials, 1 would be a quantity of illegal materials smuggled that is exactly equal to smuggling skill. It would be appropriate to consider this as the percentage of your smuggling skill that is engaged by a given occurrence of smuggling. For the sake of easy math, suppose my smuggling skill was 100, and I had 40 kg of cannabis- that would be 40% of my maximum.
Crucially, 1) there are only two variables, and 2) it is appropriate to pretend there is only one variable (% of max smuggling).
Let’s finish unpacking what’s inside the sine expression:
Sin(
((% of max smuggling) * π) - (π/ 2)
)
And after factoring:
Sin(
(% smuggling - .5)*π
)
The rest of the equation serves to shift the zero point of the sine wave and scale it down considerably. If we assume the x-axis is the percentage of max smuggling skill, and the y-axis is chance to be caught, it ends up looking like this:
Now, anyone who has done much smuggling can tell you that the likelihood of getting caught is a damn sight higher than 2%. I assume the game takes that relatively small chance to be caught and checks it many times, but I haven’t seen that code.
By saving and loading, I can confirm that I have been caught at different times after having left a city where I did some smuggling. Obviously this isn’t very scientific, but if I had to speculate, I’d say it checks it 24 times over the course of a few days. At a 2% chance over 24 checks, that yields an overall 38% chance to be caught, which feels like it’s the the ballpark. Also it would be intuitive and symmetrically pleasing code to write, consistent with other things I have seen, but again that’s pure speculation.