-4

I want to generate random points in a specific range for an opengl program, say points between the coordinates Xmin=200, Xmax = 400 and Ymin= 200 , Ymax = 400.

Actually I am trying to simulate a volcanic eruption in 2D using simple C code and without using any textures(I cannot use textures in my project). PS: I Have very basic knowledge about opengl, just a beginner.

Thanks.

dabreo
  • 53
  • 1
  • 9

2 Answers2

2

To generate randomly distributed points in a range [min, max] one can use the following formula:

(rand() % (max- min)) + min

The first part generates random numbers in the range [0, max-min] which are then shifted to [min, max] by adding min to it.

BDL
  • 21,052
  • 22
  • 49
  • 55
1

Generate random from 0 to 200 and then shift: Rand()%201+200

Vasfed
  • 18,013
  • 10
  • 47
  • 53