728x90
반응형
안녕하세요 놀이방 사장입니다.
이번 포스팅은 플러터(Flutter) 간단한 로직 연습
3번쨰 포스팅입니다.
로또 번호 생성하는 로직을 만들어볼려고 합니다.
필요한 라이브러리
import 'dart:math' as math // 별칭으로 math
import 'dart:collection';
dart : math 라이브러리는 Random() 함수를 사용하기 위해 import 했습니다.
dart : collection 은 로또번호의 특성상 중복된 값이 나오면 안되기 떄문에 hastSet 자료구조를 사용하기 위해 import 합니다.
구헌
import 'dart:math' as math // 별칭으로 math
import 'dart:collection';
void main(){
var rand = math.Random();
HashSet<int> lottoNumbers = HashSet();
while(lottoNumbers.lenth < 6){
lottoNumbers.add(rand.nextInt(45)+1);
}
print(lottoNumbers);
}
반응형