can a random number generator be used in a matrix?
조회 수: 3 (최근 30일)
이전 댓글 표시
I'm trying to make a minesweeper game in matlab so I set up a matrix A=zeros(10) and I wanted to know if I could write the code so that 1s will be randomly scattered throughout the matrix whenever the code is run.
댓글 수: 0
채택된 답변
Star Strider
2021년 12월 9일
댓글 수: 3
Steven Lord
2021년 12월 9일
Do you want a certain probability of each cell being a mine or do you want a certain fixed number of mines? In the latter case, use randperm to identify a few locations where the mines are located then fill in those locations with linear indexing.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!