Guest User

Untitled

a guest
May 16th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. SET [Color] = '#' + CONVERT(VARCHAR(max), CRYPT_GEN_RANDOM(3), 2)
  2.  
  3. SELECT concat('#',SUBSTRING((lpad(hex(round(rand() * 10000000)),6,0)),-6))
  4.  
  5. SELECT *,
  6. concat('#',SUBSTRING((lpad(hex(@curRow := @curRow + 10),6,0)),-6)) AS color
  7. FROM table
  8. INNER JOIN (SELECT @curRow := 5426175) color_start_point
  9.  
  10. CREATE FUNCTION `random_color`() RETURNS char(7) CHARSET latin1
  11. BEGIN
  12. DECLARE str CHAR(7);
  13. SET str = concat('#',SUBSTRING((lpad(hex(round(rand() * 10000000)),6,0)),-6));
  14. RETURN str;
  15. END;
  16.  
  17. INSERT INTO ... VALUES ( ... , ROUND(RAND(255 * 255 * 255)), ...)
  18.  
  19. with cte1 as (
  20. select round(round(rand(),1)*15,0) as hex1,
  21. round(round(rand(),1)*15,0) as hex2,
  22. round(round(rand(),1)*15,0) as hex3,
  23. round(round(rand(),1)*15,0) as hex4,
  24. round(round(rand(),1)*15,0) as hex5,
  25. round(round(rand(),1)*15,0) as hex6
  26. ),
  27. cte2 as (
  28. select case when hex1 = 10 then 'A'
  29. when hex1 = 11 then 'B'
  30. when hex1 = 12 then 'C'
  31. when hex1 = 13 then 'D'
  32. when hex1 = 14 then 'E'
  33. when hex1 = 15 then 'F'
  34. else str(hex1) end as hex1h,
  35. case when hex2 = 10 then 'A'
  36. when hex2 = 11 then 'B'
  37. when hex2 = 12 then 'C'
  38. when hex2 = 13 then 'D'
  39. when hex2 = 14 then 'E'
  40. when hex2 = 15 then 'F'
  41. else str(hex2) end as hex2h,
  42. case when hex3 = 10 then 'A'
  43. when hex3 = 11 then 'B'
  44. when hex3 = 12 then 'C'
  45. when hex3 = 13 then 'D'
  46. when hex3 = 14 then 'E'
  47. when hex3 = 15 then 'F'
  48. else str(hex3) end as hex3h,
  49. case when hex4 = 10 then 'A'
  50. when hex4 = 11 then 'B'
  51. when hex4 = 12 then 'C'
  52. when hex4 = 13 then 'D'
  53. when hex4 = 14 then 'E'
  54. when hex4 = 15 then 'F'
  55. else str(hex4) end as hex4h,
  56. case when hex5 = 10 then 'A'
  57. when hex5 = 11 then 'B'
  58. when hex5 = 12 then 'C'
  59. when hex5 = 13 then 'D'
  60. when hex5 = 14 then 'E'
  61. when hex5 = 15 then 'F'
  62. else str(hex5) end as hex5h,
  63. case when hex6 = 10 then 'A'
  64. when hex6 = 11 then 'B'
  65. when hex6 = 12 then 'C'
  66. when hex6 = 13 then 'D'
  67. when hex6 = 14 then 'E'
  68. when hex6 = 15 then 'F'
  69. else str(hex6) end as hex6h from cte1)
  70.  
  71. select '#'+ltrim(hex1h)+ltrim(hex2h)+ltrim(hex3h)+ltrim(hex4h)+ltrim(hex5h)+ltrim(hex6h) from cte2
  72.  
  73. SELECT '#' + CONVERT(VARCHAR(MAX), CRYPT_GEN_RANDOM(3), 2) AS Color
Add Comment
Please, Sign In to add comment