Only prohibiting certain values to be randomly selected from a certain range


Only prohibiting certain values to be randomly selected from a certain...
Author
Message
evamariav
evamariav
Associate Member (159 reputation)Associate Member (159 reputation)Associate Member (159 reputation)Associate Member (159 reputation)Associate Member (159 reputation)Associate Member (159 reputation)Associate Member (159 reputation)Associate Member (159 reputation)Associate Member (159 reputation)
Group: Forum Members
Posts: 2, Visits: 5
Dear Inquisit-users,

I was wondering if anyone could help me with changing an expression.
The expression as it is right now:
t2_var = (round(rand(2*values.t2_bmax, 2*values.t2_tmax))/2)
So what it does right now is randomly selecting a value within a range of changing bottom and top limits. By multiplying the limits with 2 and then dividing the amount by 2 it allows the value to be one within the range with increments of 0.5
However, I want the increments to be 5 and I am trying to figure out how to fix this.
I figure it should be some sort of combination between the random selection of a value between those limits ((rand(values.t2_bmax, values.t2_tmax)) and the requirement that it must be one of these values: 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95 (the limits are never lower than 0 and never higher than 100, that's why these are the only possible values). 

Could someone help me with this?
Thanks a lot in advance,

Eva



Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 104K
evamariav - Wednesday, April 19, 2017
Dear Inquisit-users,

I was wondering if anyone could help me with changing an expression.
The expression as it is right now:
t2_var = (round(rand(2*values.t2_bmax, 2*values.t2_tmax))/2)
So what it does right now is randomly selecting a value within a range of changing bottom and top limits. By multiplying the limits with 2 and then dividing the amount by 2 it allows the value to be one within the range with increments of 0.5
However, I want the increments to be 5 and I am trying to figure out how to fix this.
I figure it should be some sort of combination between the random selection of a value between those limits ((rand(values.t2_bmax, values.t2_tmax)) and the requirement that it must be one of these values: 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95 (the limits are never lower than 0 and never higher than 100, that's why these are the only possible values). 

Could someone help me with this?
Thanks a lot in advance,

Eva



Why not select a random value (integer) between 1 and 19 and multiply by 5? 1 * 5 = 5, 2 * 5 = 10, 3 * 5 = 15, ... 19 * 5 = 95.

I.e. assuming values.t2_bmax and values.t2_tmax also can only take on values in increments of 5,

t2_var = (round(rand(values.t2_bmax/5, values.t2_tmax/5))*5)
Edited 7 Years Ago by Dave
evamariav
evamariav
Associate Member (159 reputation)Associate Member (159 reputation)Associate Member (159 reputation)Associate Member (159 reputation)Associate Member (159 reputation)Associate Member (159 reputation)Associate Member (159 reputation)Associate Member (159 reputation)Associate Member (159 reputation)
Group: Forum Members
Posts: 2, Visits: 5
Dave - Thursday, April 20, 2017
evamariav - Wednesday, April 19, 2017
Dear Inquisit-users,

I was wondering if anyone could help me with changing an expression.
The expression as it is right now:
t2_var = (round(rand(2*values.t2_bmax, 2*values.t2_tmax))/2)
So what it does right now is randomly selecting a value within a range of changing bottom and top limits. By multiplying the limits with 2 and then dividing the amount by 2 it allows the value to be one within the range with increments of 0.5
However, I want the increments to be 5 and I am trying to figure out how to fix this.
I figure it should be some sort of combination between the random selection of a value between those limits ((rand(values.t2_bmax, values.t2_tmax)) and the requirement that it must be one of these values: 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95 (the limits are never lower than 0 and never higher than 100, that's why these are the only possible values). 

Could someone help me with this?
Thanks a lot in advance,

Eva



Why not select a random value (integer) between 1 and 19 and multiply by 5? 1 * 5 = 5, 2 * 5 = 10, 3 * 5 = 15, ... 19 * 5 = 95.

I.e. assuming values.t2_bmax and values.t2_tmax also can only take on values in increments of 5,

t2_var = (round(rand(values.t2_bmax/5, values.t2_tmax/5))*5)

Thanks a lot! I already figured it out with a colleague of mine, but it is good to have our solution confirmed ;)



GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search