BigInt for swift V3.5 BigIntの関数 数学関数(乱数発生関数)

 

1. 桁を指定した乱数発生関数

 

  random(digits count: Int) -> BigInt

 

    digits count : Int 桁の乱数を発生する関数

 

    

   let r1 = BigInt.random(digits: 300)//300桁の乱数を発生する

         print(r1)//→ 

536726224886957711392344177628264214671542646742308966897290394692992275760843468689352003651786134752140066246722037849215584936251664963804587103587830760320936534316928545814944834893191057496115075455086252948542736689809435741077900141330263350320058748844213694004097618591915427173757216768134

82

 

2. 範囲を指定した乱数発生関数

 

  random(in range: ClosedRange<BigInt>) -> BigInt

 

    ClosedRange<BigInt> 内の乱数を発生する関数

  

  let r2 = BigInt.random(in: 100...10000)//100...10000内の乱数を発生する

       print(r2)//→5743