Last active
          March 12, 2020 02:59 
        
      - 
      
- 
        Save forksofpower/987787c01fe1e7f897dc78e53adf66b0 to your computer and use it in GitHub Desktop. 
    Get random color value
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def random_color(code="hex") | |
| rgb = [] | |
| # generate 3 random color values | |
| 3.times {rgb << (rand() * 255).floor} | |
| # Return the rgb array or convert to hex | |
| # if hex, take into account zero padding | |
| if code === "rgb" | |
| color = rgb | |
| else | |
| color = rgb.reduce("#"){|x, y| x + ((y<=16) ? "0" : "") + y.to_s(16)} | |
| end | |
| color | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment