Number Ranges
This commit is contained in:
		
							parent
							
								
									7fa100dd65
								
							
						
					
					
						commit
						b7af339c7a
					
				
					 1 changed files with 31 additions and 0 deletions
				
			
		
							
								
								
									
										31
									
								
								ModuleScripts/Ranges.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								ModuleScripts/Ranges.lua
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,31 @@
 | 
			
		|||
-- by Sovereignty
 | 
			
		||||
 | 
			
		||||
local module = {}
 | 
			
		||||
 | 
			
		||||
local rangesRNG = Random.new()
 | 
			
		||||
 | 
			
		||||
--[[
 | 
			
		||||
    Produces a number range of integers regardless of if the input values are floats.
 | 
			
		||||
]]
 | 
			
		||||
function module.new(n1: number, n2: number): { Values: { number }, Random: (self: {}) -> (number) }
 | 
			
		||||
    local ranges: {number} = {}
 | 
			
		||||
    print(n1, n2)
 | 
			
		||||
    local first = math.min(n1, n2)
 | 
			
		||||
    local last = math.max(n1, n2)
 | 
			
		||||
    for index = math.floor(first), math.floor(last) do
 | 
			
		||||
        table.insert(ranges, index)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    local function random(): number
 | 
			
		||||
        local randomRange = ranges[rangesRNG:NextInteger(1, #ranges)]
 | 
			
		||||
        warn(randomRange)
 | 
			
		||||
        return randomRange
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    return {
 | 
			
		||||
        Values = ranges,
 | 
			
		||||
        Random = random
 | 
			
		||||
    }
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
return module
 | 
			
		||||
		Loading…
	
		Reference in a new issue