To generate array of random numbers in a given range in “C”

后端 未结 5 982
心在旅途
心在旅途 2020-12-20 08:23

i want to generate an array of random numbers for example if the range is [0,10] then the desired output to be 2 3 5 6 4 7 8 9 0 1 ( non repeatitive )

the problem

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-20 09:17

    You will have an easier time if you start out with an array with the integers 0-9 (or whatever your range is) and then randomly shuffle it. There's an example of how to do the shuffling here.

提交回复
热议问题