2011-03-09 2 views

Répondre

1
int result = (WhateverRandomNumbersComeFromInObjectiveC() >= 0.5) ? 1 : -1; 
+0

lol un bon :) – iluxa

+2

n'aimez-vous pas ces longs noms de méthode Objective-C? – Ferruccio

2
int random = arc4rand()%2 ? -1 : 1; 
1
#include <stdlib.h> 
(arc4random() % 2) * 2 - 1 
  • arc4random() donne un nombre entier aléatoire
  • (arc4random()% 2), il est soit 0 ou 1
  • (arc4random()% 2) * 2 en fait 0 ou 2
  • (arc4random()% 2) * 2 - 1 vous donne -1 ou 1
Questions connexes