Generate random number from fixed interval

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

CySam
Posts: 21
Joined: Thu Mar 27, 2014 10:23 am

Generate random number from fixed interval

Postby CySam » Mon Jun 30, 2014 10:11 pm

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?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Generate random number from fixed interval

Postby EViews Gareth » Tue Jul 01, 2014 9:09 am

Code: Select all

series rand1 = 2*@rnd-1

Code: Select all

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

CySam
Posts: 21
Joined: Thu Mar 27, 2014 10:23 am

Re: Generate random number from fixed interval

Postby CySam » Tue Jul 01, 2014 10:12 am

Ok, I got it.
Thank you very much.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests