git init
or
| \lstdefinelanguage{swift} | |
| { | |
| morekeywords={ | |
| func,if,then,else,for,in,while,do,switch,case,default,where,break,continue,fallthrough,return, | |
| typealias,struct,class,enum,protocol,var,func,let,get,set,willSet,didSet,inout,init,deinit,extension, | |
| subscript,prefix,operator,infix,postfix,precedence,associativity,left,right,none,convenience,dynamic, | |
| final,lazy,mutating,nonmutating,optional,override,required,static,unowned,safe,weak,internal, | |
| private,public,is,as,self,unsafe,dynamicType,true,false,nil,Type,Protocol, | |
| }, | |
| morecomment=[l]{//}, % l is for line comment |
| struct Random { | |
| static func within<B: protocol<Comparable, ForwardIndexType>>(range: ClosedInterval<B>) -> B { | |
| let inclusiveDistance = range.start.distanceTo(range.end).successor() | |
| let randomAdvance = B.Distance(arc4random_uniform(UInt32(inclusiveDistance.toIntMax())).toIntMax()) | |
| return range.start.advancedBy(randomAdvance) | |
| } | |
| static func within(range: ClosedInterval<Float>) -> Float { | |
| return (range.end - range.start) * Float(Float(arc4random()) / Float(UInt32.max)) + range.start | |
| } |