# Using probability distribution to generate neutrons with random selection

**URL:** <https://geant4-forum.web.cern.ch/t/using-probability-distribution-to-generate-neutrons-with-random-selection/7742>\
**Category:** Particles, Track, Event, Run and Biasing\
**Created:** [April 24, 2022, 11:53am UTC](https://geant4-forum.web.cern.ch/t/using-probability-distribution-to-generate-neutrons-with-random-selection/7742 "2022-04-24T11:53:30Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![mksharma\_iitk](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/mksharma_iitk/32/2080_2.png) [@mksharma\_iitk](https://geant4-forum.web.cern.ch/u/mksharma_iitk)\
**Post date:** [May 11, 2022, 1:18am UTC](https://geant4-forum.web.cern.ch/t/using-probability-distribution-to-generate-neutrons-with-random-selection/7742/2 "2022-05-11T01:18:47Z")

</div>

Hi Christian,

What if you store all the distributions in separate files and let the energy and angles being sampled via those files in a macro? If yes, see my response [here.](https://geant4-forum.web.cern.ch/t/how-to-implement-multiple-sources-via-gps-in-macro/6562/4). This is implemented via `GPS`, which I highly suggest as it is straightforward to implement.

With `ParticleGun` I have always generated random numbers from 0 to 1 and defined the angular range using those numbers. For example, for each event a random number is sampled, hence a random angle.

---

_[View the full topic](https://geant4-forum.web.cern.ch/t/using-probability-distribution-to-generate-neutrons-with-random-selection/7742)._
