Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#if os(Linux)
import Glibc
#elseif os(OSX)
import Darwin
#endif
import Foundation

extension Int {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
#if os(Linux)
import Glibc
#elseif os(OSX)
import Darwin
let random = arc4random
#endif
import Foundation

struct Robot {
var name: String

init() {
let numberPart = (Int(random()) % 899) + 100
let numberPart = (Int.random(in: 0..<899)) + 100
name = generateRandomLetter() + generateRandomLetter() + "\(numberPart)"
}

mutating func resetName() {
let numberPart = (Int(random()) % 899) + 100
let numberPart = (Int.random(in: 0..<899)) + 100
name = generateRandomLetter() + generateRandomLetter() + "\(numberPart)"
}
}
Expand All @@ -30,6 +25,6 @@ private func convertStringToStringArray(_ input: String) -> [String] {
private func generateRandomLetter() -> String {
let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
let letters = convertStringToStringArray(alphabet)
let randomIndex = Int(random()) % letters.count
let randomIndex = Int.random(in: 0..<letters.count)
return letters[randomIndex]
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
import Foundation

#if os(Linux)
import Glibc
#elseif os(OSX)
import Darwin
#endif

func arc4random_uniform(_ input: Int) -> Int {
#if os(Linux)
return random() % input
#elseif os(OSX)
let temp = UInt32(input)
return Int(arc4random_uniform(temp))
#endif
}

public struct Cipher {
private let abc = "abcdefghijklmnopqrstuvwxyz"
private var alphabet: [Character] { return Array(abc) }
Expand All @@ -23,7 +8,7 @@ public struct Cipher {
private func randomKeySet() -> String {
var tempKey = ""
for _ in (0..<100).enumerated() {
tempKey.append(alphabet[arc4random_uniform(alphabet.count)])
tempKey.append(alphabet[Int.random(in: 0..<alphabet.count)])
}
return tempKey
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#if os(Linux)
import Glibc
#elseif os(OSX)
import Darwin
#endif
import Foundation

extension Int {
init(_ value: Trinary) {
Expand Down