You need to use Beanshell Sampler, not Beanshell Pre-Processor.
I don't know why does JMeter allow putting Beanshell Pre-Processor at the same level as loop controller, it should go as a child of i.e. HTTP Request.
I'd also suggest to slightly change your code to be:
vars.put("myDynamicNumber", String.valueOf(someDynamicallyGeneratedNumber));
Which is more correct from Beanshell perspective.