# Create a function to generate random number in Studio X

Hi,

Can any guru out there give advice on how to create a function to generate random number in Studio X? Appreciate your advice.

Hi,

Hope the following helps you.

Note: You need to set proper random seed to Random class.

Regards,

Hi Yoichi,

Hi,

Can you try â€śOpen in Advanced Editorâ€ť in Save For Later activity as the following?

Regards,

Hi Yoichi,

Thanks for your advice! Do you know how to generate the random number as decimal?

Regards

To generate the random number in decimal, You need to change the datatype of variable from Integer to Double.

Regards

May I know the syntax? Now my syntax is (New Random).Next(36.0,37.5) which fail the validation.

Hi,

Can you try the followingďĽź

``````Saved.Values(Of Double)("SavedRandomNumber") = (New Random).NextDouble()*1.5+36
``````

or

``````Saved.Values(Of Decimal)("SavedRandomNumber") = Decimal.Parse(((New Random).NextDouble()*1.5+36).ToString)
``````

Regards,

Please find below screenshot for syntax:

Is working now and may I know how to restrict to 1 decimal place rather many decimal place?
I am using the syntax `Decimal.Parse(((New Random).NextDouble()*1.5+36).ToString)`

Hi,

Can you try `Decimal.Parse(Math.Round((New Random).NextDouble()*1.5+36,1).ToString)` ?

Regards,