OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'dart:math' as math; |
| 6 |
| 7 import '../lib/shared_messages.dart' as shared_messages; |
| 8 |
| 9 math.Random random = new math.Random(); |
| 10 |
| 11 const idLength = 6; |
| 12 final $A = "A".codeUnitAt(0); |
| 13 final $Z = "Z".codeUnitAt(0); |
| 14 |
| 15 String computeId() { |
| 16 List charCodes = []; |
| 17 for (int i = 0; i < idLength; i++) { |
| 18 charCodes.add($A + random.nextInt($Z - $A)); |
| 19 } |
| 20 return new String.fromCharCodes(charCodes); |
| 21 } |
| 22 |
| 23 /// Computes a random message ID that hasn't been used before. |
| 24 void main() { |
| 25 var usedIds = |
| 26 shared_messages.MESSAGES.values.map((entry) => entry['id']).toSet(); |
| 27 |
| 28 print("${usedIds.length} existing ids"); |
| 29 |
| 30 var newId; |
| 31 do { |
| 32 newId = computeId(); |
| 33 } while (!usedIds.contains(newId)); |
| 34 print("Available id: $newId"); |
| 35 } |
OLD | NEW |