mirror of
https://github.com/neon443/RNG_Swift.git
synced 2026-03-11 14:56:16 +00:00
implemented simpleView type in PasswordView
This commit is contained in:
89
MyApp.swift
89
MyApp.swift
@@ -11,39 +11,39 @@ struct RNGApp: App {
|
||||
|
||||
// array combiner, adds up all ints in an array
|
||||
func totalIntArr(arr: [Int]) -> Int {
|
||||
var total = 0
|
||||
for num in arr {
|
||||
total += num
|
||||
}
|
||||
return total
|
||||
var total = 0
|
||||
for num in arr {
|
||||
total += num
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
// array combiner, adds up all doubles in an array
|
||||
func totalDoubleArr(arr: [Double]) -> Double {
|
||||
var total: Double = 0
|
||||
for num in arr {
|
||||
total += num
|
||||
}
|
||||
return total
|
||||
var total: Double = 0
|
||||
for num in arr {
|
||||
total += num
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
// array combiner, adds or multiplies all ints in an array
|
||||
func arrCombine(arr: [Int], combineMode: String) -> Int {
|
||||
var output = 0
|
||||
if combineMode == "plus" {
|
||||
for num in arr {
|
||||
output += num
|
||||
}
|
||||
} else if combineMode == "multiply" {
|
||||
output = 1
|
||||
for num in arr {
|
||||
output *= num
|
||||
}
|
||||
} else {
|
||||
print("invalid combineMode '\(combineMode)'. must be 'plus' or 'multiply', returning 0")
|
||||
return 0
|
||||
}
|
||||
return output
|
||||
var output = 0
|
||||
if combineMode == "plus" {
|
||||
for num in arr {
|
||||
output += num
|
||||
}
|
||||
} else if combineMode == "multiply" {
|
||||
output = 1
|
||||
for num in arr {
|
||||
output *= num
|
||||
}
|
||||
} else {
|
||||
print("invalid combineMode '\(combineMode)'. must be 'plus' or 'multiply', returning 0")
|
||||
return 0
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
|
||||
@@ -55,25 +55,40 @@ func rng(min: Int, max: Int, step: Int) -> Int {
|
||||
}
|
||||
|
||||
func rng6Die() -> Int {
|
||||
return Int.random(in: 1...6)
|
||||
return Int.random(in: 1...6)
|
||||
}
|
||||
|
||||
func rngCDie(min: Int, max: Int) -> Int {
|
||||
return Int.random(in: min...max)
|
||||
return Int.random(in: min...max)
|
||||
}
|
||||
|
||||
func rngN6DieArr(dies: Int) -> [Int] {
|
||||
var output: [Int] = []
|
||||
for _ in 1...dies {
|
||||
output.append(rng6Die())
|
||||
}
|
||||
return output
|
||||
var output: [Int] = []
|
||||
for _ in 1...dies {
|
||||
output.append(rng6Die())
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
func rngNCDie(dies: Int, min: Int, max: Int) -> [Int] {
|
||||
var output: [Int] = []
|
||||
for _ in 1...dies {
|
||||
output.append(rngCDie(min: min, max: max))
|
||||
}
|
||||
return output
|
||||
var output: [Int] = []
|
||||
for _ in 1...dies {
|
||||
output.append(rngCDie(min: min, max: max))
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
func rngInt(len: Int) -> Int {
|
||||
var result = ""
|
||||
for _ in 1...len {
|
||||
result += String(Int.random(in: 0...9))
|
||||
}
|
||||
let resultInt = Int(result)
|
||||
return resultInt!
|
||||
}
|
||||
|
||||
func rngString(len: Int) -> String {
|
||||
let letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
return String((1..<len).map{ _ in letters.randomElement()! })
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user