1- import 'dart:io' ;
21import 'dart:math' ;
32
43import 'package:xid/src/base32codec.dart' ;
@@ -20,6 +19,7 @@ const String _allChars = "0123456789abcdefghijklmnopqrstuv";
2019///
2120class Xid {
2221 static String ? _machineId;
22+ static int ? _processId;
2323 static int ? _counterInt;
2424
2525 List <int >? _xidBytes;
@@ -77,14 +77,14 @@ class Xid {
7777 }
7878
7979 List <int > _getMachineId () {
80- var machineId = _machineId;
81- if (machineId != null ) {
82- return _toBytes (machineId );
80+
81+ if (_machineId != null ) {
82+ return _toBytes (_machineId ! );
8383 }
8484
85- machineId = Random .secure ().nextInt (5170000 ). toString ( );
86- _machineId = machineId ;
87- return _toBytes (machineId );
85+ _processId = Random .secure ().nextInt (4194304 );
86+ _machineId = Random . secure (). nextInt ( 5170000 ). toString () ;
87+ return _toBytes (_machineId ! );
8888 }
8989
9090 static int _counter () {
@@ -110,8 +110,8 @@ class Xid {
110110 _xidBytes! [5 ] = machineID[1 ];
111111 _xidBytes! [6 ] = machineID[2 ];
112112
113- _xidBytes! [7 ] = (pid >> 8 ) & 0xff ;
114- _xidBytes! [8 ] = (pid ) & 0xff ;
113+ _xidBytes! [7 ] = (_processId ! >> 8 ) & 0xff ;
114+ _xidBytes! [8 ] = (_processId ! ) & 0xff ;
115115
116116 _xidBytes! [9 ] = (counter >> 16 ) & 0xff ;
117117 _xidBytes! [10 ] = (counter >> 8 ) & 0xff ;
0 commit comments