You can generate a random sequence of the first N integer numbers and update your table with that (where N is the number of rows in your table).
Update table1 as st join (Select id, rnd_id
from (Select @rn3:=@rn3+1 as rowid, id from (select @rn3:=-1) as t4 cross join table1) as t5
join
(Select @rn2:=@rn2+1 as rowid, rnd_id from (SELECT @rn2:=-1) as t1 cross join
(Select @rn1:=@rn1+1 as rnd_id from (SELECT @rn1:=-1) as t3 cross join table1 order by Rand()) as t2) as t6
on t5.rowid=t6.rowid) as t7 on st.id=t7.id set st.random_id=t7.rnd_id;
Explanation:
(Select @rn1:=@rn1+1 as rnd_id from (SELECT @rn1:=-1) as t3 cross join table1 order by Rand()) as t2
builds the random sequence of N numbers. we use a variable that increments for each line. (SELECT @rn1:=-1) as t3 cross join is equivalent to set @rn1:=-1; we use the cross join trick to put the two statements in only one line. So this generates the sequence from 0 to N-1 and scrambles it with order by Rand()
we augment this table with a row number by
(Select @rn2:=@rn2+1 as rowid, rnd_id from (SELECT @rn2:=-1) as t1 cross join ...
we augment the original table with the row number in similar way:
(Select @rn3:=@rn3+1 as rowid, id from (select @rn3:=-1) as t4 cross join table1) as t5
and we join the two parts using the row number:
on t5.rowid=t6.rowid
We effectively built a table with a column containing the id, and another column containing the random_uid (called rnd_id) mentioned on the question. At this point we can proceed with the update, augmenting the table with our new rnd_id table and setting the random_uid in the original table (called here random_id) equal to rnd_id:
Update table1 as st join ... as t7 on st.id=t7.id set st.random_id=t7.rnd_id;
Regarding the trouble in using an update and select with the same table, i think the trick is to use different aliases for the tables. refer to MySql - Update table using select statment from same table
This solves the problem of populating the random_uid for all the table. In my case when i'd add a row, i just add a random_uid that is equal to the number of elements in the table, so N (cause i start from 0). This is good enough in my case but not in general, depending on your constraints.