SoFunction
Updated on 2025-03-05

Method for generating random strings and copying to pasteboard in Golang

Some time ago, I occasionally needed to rename certain files in my life, and they were random names.

At first, I manually renamed it and typed some alphanumeric numbers randomly on the keyboard. After a long time, I found it was quite troublesome, so I thought about whether I could use golang to implement this function and automatically transfer the generated strings.

Copy to the paste board and generate the exe file. You need to use double-click on the mouse. Do it as soon as you say it.

I searched for some relevant information online and wrote it out.

Install the necessary libraries

go get /atotto/clipboard

Code implementation

package main

import (
  "fmt"
  "/atotto/clipboard"
  "math/rand"
  "strings"
  "time"
)

var a = [...]string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
  "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}

func main() {
  s := g()
  (s)
  //Copy content to clipboard  (s)
}

func g() string {
  var builder 
  for i := 0; i < 10; i++ {
    (().UnixNano())
    (1 * )
    c := (36)
    (a[c])
  }
  return ()
}

I'm randomly generating 10 characters, you can also modify them yourself.

Finally, the exe file is generated. When you want to use it, you will find it in your pasteboard.

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.