Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a random number between 30 and 300 to an existing field

I have looked on the net as well as here but can't find an answer to the following MySQL question. I'm looking to replace the value of an existing field with a query that has a random number between 30 and 300. Reason was because I've moved galleries and had 250,000,000 views on my images and there have been lost with the migration and a lot of my members are upset that they have lost views....

like image 202
Steff Avatar asked Nov 18 '10 00:11

Steff


People also ask

How do you generate a random number in Python?

Random integer values can be generated with the randint() function. This function takes two arguments: the start and the end of the range for the generated integer values. Random integers are generated within and including the start and end of range values, specifically in the interval [start, end].

What is random number example?

Random numbers are almost always derived from a set of single-digit decimal numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. The task of generating random digits from that set of numbers by physical means is not trivial.

What is a random number generator in statistics?

A random number generator is a process that produces random numbers. Any random process (e.g., a flip of a coin or the toss of a die) can be used to generate random numbers. Stat Trek's Random Number Generator uses a statistical algorithm to produce random numbers.


2 Answers

UPDATE the_table SET the_field = the_field + FLOOR(RAND() * (270 + 1)) + 30
like image 54
AndreKR Avatar answered Sep 21 '22 18:09

AndreKR


Use RAND()

UPDATE table

SET field = FLOOR(30 + (RAND() * 270));

WHERE foo = 'bar'
like image 20
Byron Whitlock Avatar answered Sep 19 '22 18:09

Byron Whitlock