仓颉 BASE:修订间差异
跳到导航
跳到搜索
(创建页面,内容为“提供日期、随机数字、字符串操作等基础函数。 <small><small>from std import time.* from std import random.* open class BASE { let VERSION : String = "v1.0" static let tb : Int64 static init() { tb = 1234567890 } public func getVer() : String { tb VERSION } // datetime, time static public func dt() : UInt64 { _dt().toString() _dt() }…”) |
无编辑摘要 |
||
第18行: | 第18行: | ||
// datetime, time | // datetime, time | ||
public func dt() : UInt64 { | public func dt() : UInt64 { | ||
_dt().toString() | _dt().toString() | ||
第73行: | 第72行: | ||
var n1 :Int64 = BASE.tb | var n1 :Int64 = BASE.tb | ||
println("Class Property: " + BASE.tb.toString()) | println("Class Property: " + BASE.tb.toString()) | ||
let b1 = BASE(); | let b1 = BASE(); | ||
println("Method : " + b1.getVer()) | println("Method : " + b1.getVer()) |
2024年3月14日 (四) 13:21的最新版本
提供日期、随机数字、字符串操作等基础函数。
from std import time.* from std import random.* open class BASE { let VERSION : String = "v1.0" static let tb : Int64 static init() { tb = 1234567890 } public func getVer() : String { tb VERSION } // datetime, time public func dt() : UInt64 { _dt().toString() _dt() } public func dt(i : UInt64) : UInt64 { UInt64(_dt()) / UInt64(10 ** (14-i)) } public func ms() : UInt64 { UInt64(_nsec()) / UInt64(10 ** 6) } protected func _dt() : UInt64 { var now = DateTime.now() let d : Int64 = (now.year*100 + now.monthValue)*100 + now.dayOfMonth let t = (now.hour*100 + now.minute)*100 + now.second UInt64((d*1000000 + t)) } protected func _nsec() : UInt64 { var now = DateTime.now() let ms : Int64 = now.nanosecond UInt64(ms) } // rand, random public func rand() { _rand() } public func rand(l : UInt64) { //UInt64(_rand() % UInt64(10 ** l)) UInt64(_rand() / UInt64(10 ** (19 - l))) } protected func _rand() : UInt64 { let r: Random = Random() r.seed = _nsec() var i : UInt64 = 0 var flag : Bool = true while (flag) { try { i = UInt64(r.nextInt64()) if (i >= UInt64(10 ** 18)) { flag = false } else { //println("number too small.\n") } } catch (e: Exception) { //println(e) } } UInt64(i) } } main() { var n1 :Int64 = BASE.tb println("Class Property: " + BASE.tb.toString()) let b1 = BASE(); println("Method : " + b1.getVer()) println("Property: " + b1.VERSION) println("DateTime: " + b1.dt().toString()) print("random number: ") println(b1.rand()) }