Firstly please note that Simulink is under the hood generating and compiling code when you build and run a model. The Coder products do not support Code Generation for every MATLAB function. In particular, function 'makedist()' is not supported for Code Generation, otherwise this should be explicitly mentioned in the corresponding documentation page under the Section "Extended Capabilities", see the following documentation page accordingly,
If you do not need to generate standalone C/C++ code from your model, then you can use identifier 'persistent' for the probability distribution object in your state, so that the variable persists when the state goes out of scope and it is not recreated after entering the state again, and subsequently declare function 'makedist()' as 'coder.extrinsic()', such that Simulink does not generate code from this function, see also the following documentation pages accordingly,
Thus, the MATLAB code inside your Stateflow state could looks as follows,
Please note that I define variable 'u' to hold a zero value, before assigning to it the random number using function 'random()'. The reason is that Simulink does not know which type it should assign to this variable when compiling the MATLAB code, and in this way you can make sure that Simulink knows its type.
Afterwards you should be able to use variable 'u' within function 'after()' on a state transition, such as,
I hope that this information is useful for your application.