diff --git a/.swiftpm/playgrounds/CachedManifest.plist b/.swiftpm/playgrounds/CachedManifest.plist deleted file mode 100644 index 596e334..0000000 --- a/.swiftpm/playgrounds/CachedManifest.plist +++ /dev/null @@ -1,47 +0,0 @@ - - - - - CachedManifest - - manifestData - - eyJkZXBlbmRlbmNpZXMiOltdLCJkaXNwbGF5TmFtZSI6IlJORyIsInBhY2th - Z2VLaW5kIjp7InJvb3QiOnt9fSwicGxhdGZvcm1zIjpbeyJvcHRpb25zIjpb - XSwicGxhdGZvcm1OYW1lIjoiaW9zIiwidmVyc2lvbiI6IjE2LjAifV0sInBy - b2R1Y3RzIjpbeyJuYW1lIjoiUk5HIiwic2V0dGluZ3MiOlt7ImRpc3BsYXlW - ZXJzaW9uIjpbIjEuMCJdfSx7ImJ1bmRsZVZlcnNpb24iOlsiMSJdfSx7ImlP - U0FwcEluZm8iOlt7ImFjY2VudENvbG9yIjp7InByZXNldENvbG9yIjp7InBy - ZXNldENvbG9yIjp7InJhd1ZhbHVlIjoiYmx1ZSJ9fX0sImFwcENhdGVnb3J5 - Ijp7InJhd1ZhbHVlIjoicHVibGljLmFwcC1jYXRlZ29yeS51dGlsaXRpZXMi - fSwiYXBwSWNvbiI6eyJwbGFjZWhvbGRlciI6eyJpY29uIjp7InJhd1ZhbHVl - IjoiY2FsY3VsYXRvciJ9fX0sImNhcGFiaWxpdGllcyI6W10sInN1cHBvcnRl - ZERldmljZUZhbWlsaWVzIjpbInBhZCIsInBob25lIl0sInN1cHBvcnRlZElu - dGVyZmFjZU9yaWVudGF0aW9ucyI6W3sicG9ydHJhaXQiOnt9fSx7ImxhbmRz - Y2FwZVJpZ2h0Ijp7fX0seyJsYW5kc2NhcGVMZWZ0Ijp7fX0seyJwb3J0cmFp - dFVwc2lkZURvd24iOnsiY29uZGl0aW9uIjp7ImRldmljZUZhbWlsaWVzIjpb - InBhZCJdfX19XX1dfV0sInRhcmdldHMiOlsiQXBwTW9kdWxlIl0sInR5cGUi - OnsiZXhlY3V0YWJsZSI6bnVsbH19XSwidGFyZ2V0TWFwIjp7IkFwcE1vZHVs - ZSI6eyJkZXBlbmRlbmNpZXMiOltdLCJleGNsdWRlIjpbXSwibmFtZSI6IkFw - cE1vZHVsZSIsInBhY2thZ2VBY2Nlc3MiOnRydWUsInBhdGgiOiIuIiwicmVz - b3VyY2VzIjpbXSwic2V0dGluZ3MiOlt7ImtpbmQiOnsiZW5hYmxlVXBjb21p - bmdGZWF0dXJlIjp7Il8wIjoiQmFyZVNsYXNoUmVnZXhMaXRlcmFscyJ9fSwi - dG9vbCI6InN3aWZ0In1dLCJ0eXBlIjoiZXhlY3V0YWJsZSJ9fSwidGFyZ2V0 - cyI6W3siZGVwZW5kZW5jaWVzIjpbXSwiZXhjbHVkZSI6W10sIm5hbWUiOiJB - cHBNb2R1bGUiLCJwYWNrYWdlQWNjZXNzIjp0cnVlLCJwYXRoIjoiLiIsInJl - c291cmNlcyI6W10sInNldHRpbmdzIjpbeyJraW5kIjp7ImVuYWJsZVVwY29t - aW5nRmVhdHVyZSI6eyJfMCI6IkJhcmVTbGFzaFJlZ2V4TGl0ZXJhbHMifX0s - InRvb2wiOiJzd2lmdCJ9XSwidHlwZSI6ImV4ZWN1dGFibGUifV0sInRvb2xz - VmVyc2lvbiI6eyJfdmVyc2lvbiI6IjUuOS4wIn19 - - manifestHash - - ZB/SWxlchPYcczKX1JhFcosGzSflW/fzQhD7DXE27Pk= - - schemaVersion - 4 - swiftPMVersionString - 5.10.0-dev - - - diff --git a/.swiftpm/playgrounds/DocumentThumbnail.plist b/.swiftpm/playgrounds/DocumentThumbnail.plist deleted file mode 100644 index df1ad71..0000000 --- a/.swiftpm/playgrounds/DocumentThumbnail.plist +++ /dev/null @@ -1,19 +0,0 @@ - - - - - DocumentThumbnailConfiguration - - accentColorHash - - Fkd2iMDgBpnGz6RJejYS1+g8UyBitkslD+2JCBKO1Ug= - - appIconHash - - 0tSlknALCSBljl1W7VDr+qgrH0o+EF6bz9i8uwgcLoc= - - thumbnailIsPrerendered - - - - diff --git a/.swiftpm/playgrounds/DocumentThumbnail.png b/.swiftpm/playgrounds/DocumentThumbnail.png deleted file mode 100644 index 72d68a3..0000000 Binary files a/.swiftpm/playgrounds/DocumentThumbnail.png and /dev/null differ diff --git a/.swiftpm/xcode/xcuserdata/neon443.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/.swiftpm/xcode/xcuserdata/neon443.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist deleted file mode 100644 index 7b501c8..0000000 --- a/.swiftpm/xcode/xcuserdata/neon443.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ /dev/null @@ -1,6 +0,0 @@ - - - diff --git a/ContentView.swift b/ContentView.swift deleted file mode 100644 index 809dcfd..0000000 --- a/ContentView.swift +++ /dev/null @@ -1,49 +0,0 @@ -import SwiftUI - -struct ContentView: View { - var body: some View { - VStack { - NavigationSplitView { - List { - NavigationLink { - DiceView() - .navigationTitle("Dice") - } label: { - HStack { - Text("Dice") - Spacer() - Image(systemName: "die.face.1") - Image(systemName: "die.face.2.fill") - Image(systemName: "die.face.3") - Image(systemName: "die.face.4.fill") - Image(systemName: "die.face.5") - Image(systemName: "die.face.6.fill") - } - } - NavigationLink { - PasswordView() - } label: { - HStack { - Text("Password") - Spacer() - Image(systemName: "ellipsis.rectangle") - } - } - NavigationLink { - PasswordView() - } label: { - HStack { - Text("Password") - Spacer() - Image(systemName: "rectangle.and.pencil.and.ellipsis") - } - } - } - .navigationTitle("RNG") - .navigationBarTitleDisplayMode(.inline) - } detail: { - Image(systemName: "dice.fill") - } - } - } -} diff --git a/DiceView.swift b/DiceView.swift deleted file mode 100644 index 667f256..0000000 --- a/DiceView.swift +++ /dev/null @@ -1,103 +0,0 @@ -import SwiftUI - -struct DiceView: View { - @State var generated: [Int] = [0] - @State var displayDies: [Int] = [] - @State var displayMultiDieMode = "" - @State var multiDieMode = "plus" - @State var result = 0 - @State var resultDescription = "" - @State var history: [Int] = [] - let columns = [GridItem(.adaptive(minimum: 25, maximum: 75))] - @State var dies: Double = 1 - var body: some View { - VStack { - List { - Section("Number of die") { - HStack { - Text(String(Int(dies))) - Slider(value: $dies, in: 1...10, step: 1) - } - } - Section("Multi die mode") { - Picker(selection: $multiDieMode, label: Text("ioug")) { - Image(systemName: "plus").tag("plus") - Image(systemName: "multiply").tag("multiply") - }.pickerStyle(SegmentedPickerStyle()) - } - Section("Visual") { - HStack { - Spacer() - if displayDies.isEmpty { - Text("Results are visualised here when you press the generate button") - .font(.subheadline) - } else if displayDies.count != Int(dies) { - Text("Press Generate") - .font(.title) - } else { - LazyVGrid(columns: columns, spacing: 10) { - ForEach(0.. displayDies.count ? Int.random(in: 1...6) : displayDies[index])") - .resizable() - .scaledToFit() - .frame(width: 50, height: 50) - if index != displayDies.count-1 { - Image(systemName: displayMultiDieMode) - .resizable() - .scaledToFit() - .frame(width: 10, height: 10) - } - } - }.padding() - } - Spacer() - } - } - Button("Generate") { - generated = rngN6DieArr(dies: Int(dies)) - displayDies = generated - displayMultiDieMode = multiDieMode - result = arrCombine(arr: generated, combineMode: multiDieMode) - resultDescription = describeResult(inp: displayDies, combineMode: multiDieMode) - } - HStack { - Spacer() - Text(String(result)) - .bold() - .font(.largeTitle) - Spacer() - } - Text(resultDescription) - } - .listRowSpacing(5) - } - } -} - -func describeResult(inp: [Int], combineMode: String) -> String { - let len = inp.count-1 - var result = "" - var symbol = "" - if inp.isEmpty { - return "0" - } else { - if combineMode == "plus" { - symbol = " + " - } else if combineMode == "multiply" { - symbol = " x " - } - for i in 0...len { - if i == len { - result += String(inp[i]) - } else { - result += String(inp[i]) + symbol - } - } - result += " = " + String(arrCombine(arr: inp, combineMode: combineMode)) - return result - } -} - -#Preview { - DiceView() -} diff --git a/MyApp.swift b/MyApp.swift deleted file mode 100644 index 8cbbd8e..0000000 --- a/MyApp.swift +++ /dev/null @@ -1,94 +0,0 @@ -import SwiftUI - -@main -struct RNGApp: App { - var body: some Scene { - WindowGroup { - ContentView() - } - } -} - -// 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 -} - -// 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 -} - -// 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 -} - - -func rng(min: Int, max: Int, step: Int) -> Int { - let range = (max - min) / step + 1 - var rng = Int.random(in: 0.. Int { - return Int.random(in: 1...6) -} - -func rngCDie(min: Int, max: Int) -> Int { - return Int.random(in: min...max) -} - -func rngN6DieArr(dies: Int) -> [Int] { - 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 -} - -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.. String { - var result = "" - if type == "4Int" { - result = String(rngInt(len: 4)) - } else if type == "6Int" { - result = String(rngInt(len: 6)) - } else if type == "4String" { - result = rngString(len: 4) - } else if type == "6String" { - result = rngString(len: 6) - } else if min != nil && max != nil { - if type == "Int" { - result = String(rngInt(len: max! - min!) + min!) - } else if type == "String" { - if min == nil { - //if there no min, use max as length - result = rngString(len: max!) - } else { - print("when type is String, leave min empty and use max as a length.") - print("returning -1") - } - } - } else { - print("invalid input") - print("type = Int: give min and max") - print("type = String: min = nil, max = length") - print("Preset: (type = 4Int/String, 6Int/String) and leave min, max = nil") - print(" 4Int: 0000-9999; 4 digit") - print(" 6Int: 000000-999999; 6 digit") - print(" 4String: a-z/0-9: _ _ _ _; 4 digit alphanumeric") - print(" 6String: a-z/0-9: _ _ _ _ _ _; 6 digit alphanumeric") - print("returning -1") - result = "-1" - } - return result -} - -#Preview("PasswordView") { - PasswordView() -} -#Preview("PassCodeWordHelpView") { - PassCodeWordHelpView() -} diff --git a/RNG.xcodeproj/project.pbxproj b/RNG.xcodeproj/project.pbxproj new file mode 100644 index 0000000..df8ddc0 --- /dev/null +++ b/RNG.xcodeproj/project.pbxproj @@ -0,0 +1,376 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXBuildFile section */ + A9794C832CB70ADA00527984 /* RNGApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9794C822CB70ADA00527984 /* RNGApp.swift */; }; + A9794C852CB70ADA00527984 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9794C842CB70ADA00527984 /* ContentView.swift */; }; + A9794C872CB70AE100527984 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A9794C862CB70AE100527984 /* Assets.xcassets */; }; + A9794C8B2CB70AE100527984 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A9794C8A2CB70AE100527984 /* Preview Assets.xcassets */; }; + A9794C922CB70BF600527984 /* DiceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9794C912CB70BF600527984 /* DiceView.swift */; }; + A9794C942CB70C1400527984 /* NumberView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9794C932CB70C1400527984 /* NumberView.swift */; }; + A9794C962CB70C8000527984 /* PasswordView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9794C952CB70C8000527984 /* PasswordView.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + A9794C7F2CB70ADA00527984 /* RNG.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RNG.app; sourceTree = BUILT_PRODUCTS_DIR; }; + A9794C822CB70ADA00527984 /* RNGApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNGApp.swift; sourceTree = ""; }; + A9794C842CB70ADA00527984 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; + A9794C862CB70AE100527984 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + A9794C882CB70AE100527984 /* RNG.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = RNG.entitlements; sourceTree = ""; }; + A9794C8A2CB70AE100527984 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; + A9794C912CB70BF600527984 /* DiceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiceView.swift; sourceTree = ""; }; + A9794C932CB70C1400527984 /* NumberView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NumberView.swift; sourceTree = ""; }; + A9794C952CB70C8000527984 /* PasswordView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordView.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + A9794C7C2CB70ADA00527984 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + A9794C762CB70ADA00527984 = { + isa = PBXGroup; + children = ( + A9794C812CB70ADA00527984 /* RNG */, + A9794C802CB70ADA00527984 /* Products */, + ); + sourceTree = ""; + }; + A9794C802CB70ADA00527984 /* Products */ = { + isa = PBXGroup; + children = ( + A9794C7F2CB70ADA00527984 /* RNG.app */, + ); + name = Products; + sourceTree = ""; + }; + A9794C812CB70ADA00527984 /* RNG */ = { + isa = PBXGroup; + children = ( + A9794C822CB70ADA00527984 /* RNGApp.swift */, + A9794C842CB70ADA00527984 /* ContentView.swift */, + A9794C952CB70C8000527984 /* PasswordView.swift */, + A9794C912CB70BF600527984 /* DiceView.swift */, + A9794C932CB70C1400527984 /* NumberView.swift */, + A9794C862CB70AE100527984 /* Assets.xcassets */, + A9794C882CB70AE100527984 /* RNG.entitlements */, + A9794C892CB70AE100527984 /* Preview Content */, + ); + path = RNG; + sourceTree = ""; + }; + A9794C892CB70AE100527984 /* Preview Content */ = { + isa = PBXGroup; + children = ( + A9794C8A2CB70AE100527984 /* Preview Assets.xcassets */, + ); + path = "Preview Content"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + A9794C7E2CB70ADA00527984 /* RNG */ = { + isa = PBXNativeTarget; + buildConfigurationList = A9794C8E2CB70AE100527984 /* Build configuration list for PBXNativeTarget "RNG" */; + buildPhases = ( + A9794C7B2CB70ADA00527984 /* Sources */, + A9794C7C2CB70ADA00527984 /* Frameworks */, + A9794C7D2CB70ADA00527984 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = RNG; + productName = RNG; + productReference = A9794C7F2CB70ADA00527984 /* RNG.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + A9794C772CB70ADA00527984 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1540; + LastUpgradeCheck = 1540; + TargetAttributes = { + A9794C7E2CB70ADA00527984 = { + CreatedOnToolsVersion = 15.4; + }; + }; + }; + buildConfigurationList = A9794C7A2CB70ADA00527984 /* Build configuration list for PBXProject "RNG" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = A9794C762CB70ADA00527984; + productRefGroup = A9794C802CB70ADA00527984 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + A9794C7E2CB70ADA00527984 /* RNG */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + A9794C7D2CB70ADA00527984 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + A9794C8B2CB70AE100527984 /* Preview Assets.xcassets in Resources */, + A9794C872CB70AE100527984 /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + A9794C7B2CB70ADA00527984 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + A9794C962CB70C8000527984 /* PasswordView.swift in Sources */, + A9794C852CB70ADA00527984 /* ContentView.swift in Sources */, + A9794C922CB70BF600527984 /* DiceView.swift in Sources */, + A9794C942CB70C1400527984 /* NumberView.swift in Sources */, + A9794C832CB70ADA00527984 /* RNGApp.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + A9794C8C2CB70AE100527984 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + A9794C8D2CB70AE100527984 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SWIFT_COMPILATION_MODE = wholemodule; + }; + name = Release; + }; + A9794C8F2CB70AE100527984 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = RNG/RNG.entitlements; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"RNG/Preview Content\""; + DEVELOPMENT_TEAM = 8626DL2GW3; + ENABLE_HARDENED_RUNTIME = YES; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphoneos*]" = UIStatusBarStyleDefault; + "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 16; + LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; + "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 13; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.neon443.RNG; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = auto; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + A9794C902CB70AE100527984 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = RNG/RNG.entitlements; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"RNG/Preview Content\""; + DEVELOPMENT_TEAM = 8626DL2GW3; + ENABLE_HARDENED_RUNTIME = YES; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphoneos*]" = UIStatusBarStyleDefault; + "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 16; + LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; + "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 13; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.neon443.RNG; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = auto; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + A9794C7A2CB70ADA00527984 /* Build configuration list for PBXProject "RNG" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + A9794C8C2CB70AE100527984 /* Debug */, + A9794C8D2CB70AE100527984 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + A9794C8E2CB70AE100527984 /* Build configuration list for PBXNativeTarget "RNG" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + A9794C8F2CB70AE100527984 /* Debug */, + A9794C902CB70AE100527984 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = A9794C772CB70ADA00527984 /* Project object */; +} diff --git a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata b/RNG.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 100% rename from .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata rename to RNG.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/.swiftpm/xcode/xcuserdata/neon443.xcuserdatad/xcschemes/xcschememanagement.plist b/RNG.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 55% rename from .swiftpm/xcode/xcuserdata/neon443.xcuserdatad/xcschemes/xcschememanagement.plist rename to RNG.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist index deb4913..18d9810 100644 --- a/.swiftpm/xcode/xcuserdata/neon443.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/RNG.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -2,13 +2,7 @@ - SchemeUserState - - RNG.xcscheme_^#shared#^_ - - orderHint - 0 - - + IDEDidComputeMac32BitWarning + diff --git a/RNG.xcodeproj/xcshareddata/xcschemes/RNG.xcscheme b/RNG.xcodeproj/xcshareddata/xcschemes/RNG.xcscheme new file mode 100644 index 0000000..8c25fdc --- /dev/null +++ b/RNG.xcodeproj/xcshareddata/xcschemes/RNG.xcscheme @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RNG/Assets.xcassets/AccentColor.colorset/Contents.json b/RNG/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 0000000..eb87897 --- /dev/null +++ b/RNG/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/RNG/Assets.xcassets/AppIcon.appiconset/Contents.json b/RNG/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..532cd72 --- /dev/null +++ b/RNG/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,63 @@ +{ + "images" : [ + { + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "16x16" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "16x16" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "32x32" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "32x32" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "128x128" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "128x128" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "256x256" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "256x256" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "512x512" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "512x512" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/RNG/Assets.xcassets/Contents.json b/RNG/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/RNG/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/RNG/ContentView.swift b/RNG/ContentView.swift new file mode 100644 index 0000000..6d2721d --- /dev/null +++ b/RNG/ContentView.swift @@ -0,0 +1,59 @@ +// +// ContentView.swift +// RNG +// +// Created by Nihaal on 09/10/2024. +// + +import SwiftUI + +struct ContentView: View { + var body: some View { + VStack { + NavigationSplitView { + List { + NavigationLink { + NumberView() + .navigationTitle("Random Number Generator") + } label: { + HStack { + Text("Random Number Generator") + Spacer() + Image(systemName: "textformat.123") + } + } + NavigationLink { + DiceView() + .navigationTitle("Dice") + } label: { + HStack { + Text("Dice") + Spacer() + Image(systemName: "die.face.1") + Image(systemName: "die.face.2.fill") + Image(systemName: "die.face.3") + Image(systemName: "die.face.4.fill") + Image(systemName: "die.face.5") + Image(systemName: "die.face.6.fill") + } + } + NavigationLink { + PasswordView() + .navigationTitle("Password") + } label: { + HStack { + Text("Password") + Spacer() + Image(systemName: "rectangle.and.pencil.and.ellipsis") + } + } + } + .navigationTitle("RNG") + .navigationBarTitleDisplayMode(.inline) + } detail: { + Image(systemName: "dice.fill") + } + } + } +} + diff --git a/RNG/DiceView.swift b/RNG/DiceView.swift new file mode 100644 index 0000000..5b955a3 --- /dev/null +++ b/RNG/DiceView.swift @@ -0,0 +1,114 @@ +// +// DiceView.swift +// RNG +// +// Created by Nihaal on 30/05/2024. +// + +import SwiftUI + +struct DiceView: View { + @State var generated: [Int] = [0] + @State var displayDies: [Int] = [] + @State var displayMultiDieMode = "" + @State var multiDieMode = "plus" + @State var result = 0 + @State var resultDescription = "" + @State var history: [Int] = [] + let columns = [GridItem(.adaptive(minimum: 25, maximum: 75))] + @State var dies: Double = 2 + var body: some View { + VStack { + List { + Section("Number of die") { + HStack { + Text( String( Int(dies) ) ) + .font(.system(size: 25, weight: .bold)) + Divider() + Text("1") + Slider(value: $dies, in: 1...20, step: 1) + Text("20") + } + } + Section("Multi die mode") { + Picker(selection: $multiDieMode, label: Text("ioug")) { + Image(systemName: "plus").tag("plus") + Image(systemName: "multiply").tag("multiply") + }.pickerStyle(SegmentedPickerStyle()) + } + Section("Visual") { + HStack { + Spacer() + if displayDies.isEmpty { + Text("Results are visualised here when you press the generate button") + .font(.subheadline) + } else { + LazyVGrid(columns: columns, spacing: 10) { + ForEach(0.. String { + let len = inp.count-1 + var result = "" + var symbol = "" + if inp.isEmpty { + return "0" + } else { + if combineMode == "plus" { + symbol = " + " + } else if combineMode == "multiply" { + symbol = " x " + } + for i in 0...len { + if i == len { + result += String(inp[i]) + } else { + result += String(inp[i]) + symbol + } + } + result += " = " + String(arrCombine(arr: inp, combineMode: combineMode)) + return result + } +} + +#Preview { + DiceView() +} diff --git a/RNG/NumberView.swift b/RNG/NumberView.swift new file mode 100644 index 0000000..7371f74 --- /dev/null +++ b/RNG/NumberView.swift @@ -0,0 +1,175 @@ +// +// RNGView.swift +// RNG +// +// Created by Nihaal on 09/10/2024. +// + + + + + + + + + + +//fix date created +//TODO: readd ios 16 support +//TODO: try to use inject + + + + + + + +import SwiftUI + +struct NumberView: View { + @State var low: String = "1" + @State var high: String = "10" + @State var exclude: String = "none" + @State var generated = "5" + @State var prevGen = "" + @State var generatedInt: Int = 0 + @State var prevGenInt: Int = 0 + @State var dispResult = 5 + var body: some View { + List { + HStack { + Spacer() + TextField("From", text: $low) + .keyboardType(.numberPad) + .textFieldStyle(RoundedBorderTextFieldStyle()) + .multilineTextAlignment(.center) + Image(systemName: "minus") + .resizable() + .scaledToFit() + .bold() + .frame(width: 20) + TextField("To", text: $high) + .keyboardType(.numberPad) + .textFieldStyle(RoundedBorderTextFieldStyle()) + .multilineTextAlignment(.center) + Spacer() + } + Section("Exclude") { + Picker(selection: $exclude, label: Text("")) { + Text("Start").tag("start") + Text("None").tag("none") + Text("End").tag("end") + Text("Both").tag("both") + } + .pickerStyle(.segmented) + } + Section("Description") { + Text(describeInputs(min: low, max: high, exclude: exclude)) + } + } + Text(String(dispResult)) + .font(.system(size: 75, weight: .bold)) + .foregroundColor(.gray) + .frame(height: 50) + Button { + prevGen = generated + generated = rng2(min: low, max: high, exclude: exclude) + prevGenInt = Int(prevGen)! + generatedInt = Int(generated)! + if prevGenInt < generatedInt { + for _ in prevGenInt...generatedInt { + dispResult += 1 + //sleep( UInt32( 1 / (generatedInt - prevGenInt) ) ) + } + } else if prevGenInt > generatedInt { + for _ in generatedInt...prevGenInt { + dispResult -= 1 + //sleep( UInt32( 1 / (prevGenInt - generatedInt) ) ) + } + } else if prevGenInt == generatedInt { + dispResult = generatedInt + } + } label: { + Text("Generate") + .padding(.horizontal) + .font(.system(size: 25, weight: .bold)) + } + .buttonStyle(BorderedProminentButtonStyle()) + .cornerRadius(15) + .padding(.bottom) + } +} + +func describeInputs(min: String, max: String, exclude: String) -> String { + let validExcludes = ["start", "end", "both", "none"] + guard validExcludes.contains(exclude) else { + print("invalid exclude: " + exclude) + return "invalid exclude: " + exclude + } + + var result = "Any number from " + result += min != "" ? min : "_" + result += " to " + result += max != "" ? max : "_" + + if min == "" || max == "" { + return "Enter values above." + } else { + switch exclude { + case "start": + result += ", excluding \(min)" + case "end": + result += ", excluding \(max)" + case "both": + result += ", excluding \(min) and \(max)" + case "none": + break + default: + result = "invalid 'exclude'" + } + } + result += "." + return result +} + +enum rng2Errors: Error { + case h +} + +func rng2(min: String, max: String, exclude: String) -> String { + guard min != "" || max != "" else { + return "Enter values above." + } + guard var minInt = Int(min) else { + print("invalid min") + return "-1" + } + guard var maxInt = Int(max), maxInt >= minInt else { + print("invalid max or is less than min") + return "-1" + } + guard exclude != "both", min != max else { + print("excluding both but min == max") + return "No possible numbers, both bounds equal." + } + let minIntPlus1 = minInt + 1 + guard exclude != "both", minIntPlus1 != maxInt else { + print("excluding both but min +1 == max") + return "No possible numbers." + } + var generated = 0 + if exclude == "both" { + maxInt -= 1 + minInt += 1 + } else if exclude == "start" { + minInt += 1 + } else if exclude == "end" { + maxInt -= 1 + } + generated = rng(min: minInt, max: maxInt) + return String(generated) +} + +#Preview { + NumberView() +} diff --git a/RNG/PasswordView.swift b/RNG/PasswordView.swift new file mode 100644 index 0000000..2c6807c --- /dev/null +++ b/RNG/PasswordView.swift @@ -0,0 +1,122 @@ +// +// PasswordView.swift +// RNG +// +// Created by Nihaal on 30/05/2024. +// + +import SwiftUI + +struct PasswordView: View { + @State var selectedOptions: [PassOption] = [] + let options: [PassOption] = [ + PassOption(name: "0-9", chars: Array("0123456789")), + PassOption(name: "a-z", chars: Array("abcdefghijklmnopqrstuvwxyz")), + PassOption(name: "A-Z", chars: Array("ABCDEFGHIJKLMNOPQRSTUVWXYZ")) + ] + @State var presetLen = 4 + @State var customLen = 8 + @State var generated = "" + @State var result = "" + @State var history: [Int] = [] + + var body: some View { + VStack { + List { + Text("Hello, world!") + .font(.largeTitle) + .foregroundColor(.white) + .padding() + .background(Color.blue) + .padding() + .background(Color.mint) + .padding() + .background(Color.green) + + Section("Include") { + ForEach(options) { option in + Toggle(isOn: Binding( + get: { + self.selectedOptions.contains(where: { $0.id == option.id }) + }, + set: { isSelected in + if isSelected { + self.selectedOptions.append(option) + } else { + self.selectedOptions.removeAll { $0.id == option.id } + } + } + )) { + Text(option.name) + } + } + } + + Section("Length") { + Picker("", selection: $presetLen) { + Text("4").tag(4) + Text("6").tag(6) + Text("Custom: \(customLen)").tag(-1) + } + .pickerStyle(SegmentedPickerStyle()) + } + + if presetLen == -1 { + TextField("Custom", value: $customLen, formatter: NumberFormatter()) + .keyboardType(.numberPad) + .frame(width: 50) + } + + Text(String(result)) + .font(.system(size: 75, weight: .bold)) + .foregroundColor(.gray) + .frame(height: 50) + + Text(String(generated)) + .font(.system(size: 75, weight: .bold)) + .foregroundColor(.gray) + .frame(height: 50) + + Button { + generated = genPass(selectdOpts: selectedOptions, len: (presetLen == -1 ? customLen : presetLen)) + } label: { + Text("Generate") + .padding(.horizontal) + .font(.system(size: 25, weight: .bold)) + } + .buttonStyle(BorderedProminentButtonStyle()) + .cornerRadius(15) + .padding(.vertical) + } + } + } +} +struct Option: Identifiable { + let id: Int + let name: String +} + +struct PassOption: Identifiable { + var id = UUID() + var name: String + var chars: [Character] +} + +func genPass(selectdOpts: [PassOption], len: Int) -> String { + let characters = selectdOpts.flatMap { $0.chars } + + guard !(characters.isEmpty) else { + print("characters empty") + return "" + } + + return (0.. - AppSettings - - appIconPlaceholderGlyphName - calculator - appSettingsVersion - 1 - + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + diff --git a/RNG/RNGApp.swift b/RNG/RNGApp.swift new file mode 100644 index 0000000..dfc8044 --- /dev/null +++ b/RNG/RNGApp.swift @@ -0,0 +1,110 @@ +// +// RNGApp.swift +// RNG +// +// Created by Nihaal on 24/05/2024. +// + +import SwiftUI + +@main +struct RNGApp: App { + var body: some Scene { + WindowGroup { + ContentView() + } + } +} + +// 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 +} + +// 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 +} + +// 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 +} + + +func rng(min: Int, max: Int) -> Int { + var rng = 0 + rng = Int.random(in: min...max) + return rng +} + +func rng6Die() -> Int { + return Int.random(in: 1...6) +} + +func rngCDie(min: Int, max: Int) -> Int { + return Int.random(in: min...max) +} + +func rngN6DieArr(dies: Int) -> [Int] { + 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 +} + +func rngInt(len: Int) async -> Int { + var resultI: Int = 0 + var latestElement = 0 + for _ in 1...len { + latestElement = Int.random(in: 0...9) + if latestElement == 0 { + resultI *= 10 + } else { + resultI *= 10 + resultI += latestElement + } + } + return resultI +} + +func rngString(len: Int) -> String { + let letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + return String((1..