array_shuffle

SinceVersion 2.0

array_shuffle shuffle

description

Syntax

  1. ARRAY<T> array_shuffle(ARRAY<T> array1, [INT seed])
  2. ARRAY<T> shuffle(ARRAY<T> array1, [INT seed])

Randomly arrange the elements in the array. Among them, the parameter array1 is the array to be randomly arranged, and the optional parameter seed is to set the initial value used by the pseudo-random number generator to generate pseudo-random numbers. Shuffle has the same function as array_shuffle.

  1. array_shuffle(array1);
  2. array_shuffle(array1, 0);
  3. shuffle(array1);
  4. shuffle(array1, 0);

example

  1. mysql [test]> select c_array1, array_shuffle(c_array1) from array_test;
  2. +-----------------------+---------------------------+
  3. | c_array1 | array_shuffle(`c_array1`) |
  4. +-----------------------+---------------------------+
  5. | [1, 2, 3, 4, 5, NULL] | [2, NULL, 5, 3, 4, 1] |
  6. | [6, 7, 8, NULL] | [7, NULL, 8, 6] |
  7. | [1, NULL] | [1, NULL] |
  8. | NULL | NULL |
  9. +-----------------------+---------------------------+
  10. 4 rows in set (0.01 sec)
  11. MySQL [test]> select c_array1, array_shuffle(c_array1, 0) from array_test;
  12. +-----------------------+------------------------------+
  13. | c_array1 | array_shuffle(`c_array1`, 0) |
  14. +-----------------------+------------------------------+
  15. | [1, 2, 3, 4, 5, NULL] | [1, 3, 2, NULL, 4, 5] |
  16. | [6, 7, 8, NULL] | [6, 8, 7, NULL] |
  17. | [1, NULL] | [1, NULL] |
  18. | NULL | NULL |
  19. +-----------------------+------------------------------+
  20. 4 rows in set (0.01 sec)

keywords

ARRAY,ARRAY_SHUFFLE,SHUFFLE