APS Excellence in Physics Education Award
November 2019

Education Prize Logo
Science SPORE Prize
November 2011

NSF Logo
The Open Source Physics Project is supported by NSF DUE-0442581.

Problem with code in On Release of a Slider View

Return to the EJS Modeling forum
Login to post to this thread

Function to return an integer problem
Eoghan Miggan
1 Posts

Hey, so I wrote a function to get a random number between two value ranges as so:

public int getRandomNumber(int lowest, int highest){

int num = highest - lowest;

Random rand = new Random();
int i = rand.nextInt(num) + lowest;

return i;


For example if I was to say N = getRandomNumber(340, 385); and call this in the evolution page then it works and returns a random number between 340-385 over and over and over when play() it clicked.

But when I call this function in the On Release code of a Slider view, it only returns int's of values 1-9.

Does anyone know why this is?

OSP Projects:
Open Source Physics - EJS Modeling
Physlet Physics
Physlet Quantum Physics
STP Book