rand() again

This is a discussion on rand() again within the C Programming forums, part of the General Programming Boards category; Can anyone tell me how can i get rand numbers between [-1,1] using rand???...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    7

    rand() again

    Can anyone tell me how can i get rand numbers between [-1,1] using rand???

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If you have a number between 0 and 1 (which assuming you got through the last question) can you think of some sort of way to turn 0 into -1, and 0.5 into 0, and 1 into 1? (You've got three points, see what kind of shape they make....)

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Can anyone tell me how can i get rand numbers between [-1,1] using rand???
    Maybe get rand numbers between [0,2] and subtract 1???
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Apr 2010
    Posts
    7

    rand() again

    thx guys...i got it!

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21