투케이2K

64. (Flutter/플러터) [Mac] : [Dart] : 다트 - [math] Random nextInt 랜덤 정수 값 출력 본문

Flutter

64. (Flutter/플러터) [Mac] : [Dart] : 다트 - [math] Random nextInt 랜덤 정수 값 출력

투케이2K 2024. 5. 29. 20:15
반응형

[개발 환경 설정]

개발 툴 : AndroidStudio

개발 언어 : Dart

 

[소스 코드]

import 'package:flutter/material.dart';
import 'dart:developer';
import 'dart:math';


// -----------------------------------------------------------------------------------------
// TODO [main] : [application 의 진입점 역할]
// -----------------------------------------------------------------------------------------
void main() {

  /**
   * ------------------------------------------------
   * [요약 설명]
   * ------------------------------------------------
   * 1. 필요 import : import 'dart:math';
   * ------------------------------------------------
   * 2. math 참고 사이트 : https://api.dart.dev/stable/3.4.1/dart-math/dart-math-library.html
   * ------------------------------------------------
   * */


  try {

    // [초기 변수 선언]
    // Random().nextInt(10) + 1; // 1부터 10개
    var intValue = Random().nextInt(10); // Value >= 0 and < 10


    // [로그 출력 수행]
    print("intValue :: ${intValue}");

  }
  catch (e) {
    print("Catch :: ${e}");
  }

}
 

[결과 출력]


반응형
Comments