Emerging devices, such as magnetic tunnel junctions, are key for energy-efficient, performant future computing systems. However, designing devices with the desirable specification and performance for these applications is often found to be time-consuming and non-trivial. Here, we investigate the design and optimization of spin-orbit torque and spin transfer torque magnetic tunnel junction models as the probabilistic devices for true random number generation. We leverage reinforcement learning and evolutionary optimization to vary key device and material properties of the various device models for stochastic operation. Our artificial-intelligence-guided codesign methods generated different candidate devices capable of generating stochastic samples for a desired probability distribution, while also minimizing energy usage for the devices. This framework can also be applied to other devices and applications.