-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom.ex
51 lines (38 loc) · 927 Bytes
/
random.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
defmodule Random do
@moduledoc """
Documentation for Project1.
"""
@doc """
Hello world.
## Examples
iex> Project1.hello
:world
"""
def base62(num_bytes \\ 16) do
random_bytes(num_bytes)
|> Base.encode64(padding: false)
|> String.replace(~r/[+\/]/, random_char())
end
@base62_alphabet 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
defp random_char do
[Enum.random(@base62_alphabet)] |> to_string
end
def generateInput() do
IO.puts "gererating random inputs inside random"
"kanikagupta"<>base62()
end
def calculateHash(input) do
:crypto.hash(:sha256, input) |> Base.encode16
end
defp random_bytes(num) do
:crypto.strong_rand_bytes(num)
end
def check_leading_zeros(input, tzero,lzero) do
linput=String.slice(input,0..lzero-1)
if tzero==linput do
true
else
false
end
end
end