vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I need to generate a random value from x to y having increment i. where x is start value, y is end value. so if x = 2 and y = 12 and i = 2 then random value should be generated from the following set (2,4,6,8,10,12) and if x = 1 then random number should be picked from the following set (1,3,5,7,9,11) I need to know both in MySQL and PHP and will choose whichever is simpler. Thanks. |
| |||
| ..oO(Cosmic programmer) >I need to generate a random value from x to y having increment i. >where x is start value, y is end value. > >so if x = 2 and y = 12 and i = 2 > >then random value should be generated from the following set > >(2,4,6,8,10,12) > >and if x = 1 then random number should be picked from the following set > >(1,3,5,7,9,11) > >I need to know both in MySQL and PHP and will choose whichever is simpler. Read about 'for' loops. Micha |
| ||||
| "Cosmic programmer" <not-my-email@nowhere.com> wrote in message news:fuum46$9as$1@registered.motzarella.org... > > I need to generate a random value from x to y having increment i. > where x is start value, y is end value. > > so if x = 2 and y = 12 and i = 2 > > then random value should be generated from the following set > > (2,4,6,8,10,12) > > and if x = 1 then random number should be picked from the following set > > (1,3,5,7,9,11) > > I need to know both in MySQL and PHP and will choose whichever is simpler. > > Thanks. > > Got it! in MySQL start_val + inc * floor(rand()*(floor((end_val-start_val)/inc + 1))) I'm a genious!!! |