Page 1 of 1

Generate random number from fixed interval

Posted: Mon Jun 30, 2014 10:11 pm
by CySam
Hi, if I want to generate a series of random number which is only draw from a given interval, e.g. random number from interval [-1,1]. How should I write in the program code?

Another question is, if I only want to draw some fixed number randomly, example I only want to draw a number from 2 fixed numbers i.e. -1 and 1 randomly, how should I write in my program code?

Re: Generate random number from fixed interval

Posted: Tue Jul 01, 2014 9:09 am
by EViews Gareth

Code: Select all

series rand1 = 2*@rnd-1

Code: Select all

series rand2 = @rnd>0.5 rand2 = rand2*1 + (1-rand2)*(-1)

Re: Generate random number from fixed interval

Posted: Tue Jul 01, 2014 10:12 am
by CySam
Ok, I got it.
Thank you very much.