randomize in c language

determine how many throws of dice will result to a snake eye

Page 1 of 1

1 Replies - 2210 Views - Last Post: 21 February 2010 - 05:07 AM Rate Topic: -----

#1 lizzylynx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-February 10

randomize in c language

Posted 21 February 2010 - 03:23 AM

i dont know to use randomize in determining how many throws of dice that will result i a snake eye.
Is This A Good Question/Topic? 0
  • +

Replies To: randomize in c language

#2 DoubleFission  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 24
  • View blog
  • Posts: 223
  • Joined: 20-September 08

Re: randomize in c language

Posted 21 February 2010 - 05:07 AM

You need to use the rand() function...


// Write your generic program start parts here

srand(time(NULL)); // This 'seeds' the random number generator

// This is where you calculate how many times it takes... (Maybe a loop of some description)

// Randomly generate 2 numbers between 1-6

// Check if they are both 1, if so you have snake eyes...




The way you get random numbers between 2 specified values is:

rand() % <Range of possible values> + <Min number>

in this case the range is 6: 1, 2, 3, 4, 5, 6
and the minimum number is 1....

Hope that gives you all the understanding of how rand() works
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1