Generating Unique Random Numbers in an Array using Loop

后端 未结 6 2034
臣服心动
臣服心动 2020-12-12 01:36

So the question is to develop a [5][5] table, each containing unique numbers from 1-100 (no duplicates)

so here\'s what I came up with:

#inc         


        
6条回答
  •  醉话见心
    2020-12-12 02:03

    Think of it like a deck of 100 cards.

    • Create a 100 element array holding the card numbers (1..100)
    • Shuffle the array (=deck). (see @koodawg's answer and @Steve314's comment)
    • "Deal" yourself the first 25 cards off the deck, into your 5x5 array.

提交回复
热议问题