nombre aléatoire

nombre aléatoire - C - Programmation

Marsh Posté le 24-08-2004 à 22:03:05    

est il possible en c ou en c++ de mettre un nombre aléatoire dans un variable ?
et que le nombre change a chaque execution du prog ?
 
merci pour vos réponses :wahoo:

Reply

Marsh Posté le 24-08-2004 à 22:03:05   

Reply

Marsh Posté le 24-08-2004 à 22:08:43    

Version C : http://dejean.benoit.free.fr/code/rand.c.html
Version C++ : http://dejean.benoit.free.fr/code/rand.cpp.html
 
Tout cela provient de Taz, un intervenant de ce forum.

Reply

Marsh Posté le 24-08-2004 à 22:17:39    

et ca corespond a quoi RAND_MAX ???

Reply

Marsh Posté le 24-08-2004 à 22:28:19    

à RAND_MAX ... rand() renvoie un entier non-signé sur entre 0 et RAND_MAX

Reply

Marsh Posté le 24-08-2004 à 22:32:35    

Code :
  1. #include <stdlib.h> /* pour srand, rand et RAND_MAX */


donc RAND_MAX est défini dans stdlib.h, et il est egal a combien ?


Message édité par blastrock le 24-08-2004 à 22:33:59
Reply

Marsh Posté le 24-08-2004 à 22:34:57    

BlastRock a écrit :


donc RAND_MAX est défini dans stdlib.h, et il est egal a combien ?


 
Regarde dans ce fichier pour le savoir ;)

Reply

Marsh Posté le 24-08-2004 à 22:44:06    

BlastRock a écrit :

Code :
  1. #include <stdlib.h> /* pour srand, rand et RAND_MAX */


donc RAND_MAX est défini dans stdlib.h, et il est egal a combien ?

à RAND_MAX

Reply

Marsh Posté le 24-08-2004 à 22:46:23    

Citation :

rand() renvoie un entier non-signé sur entre 0 et RAND_MAX


et comment on le change ce RAND_MAX ?
faut faire #undef RAND_MAX et #define RAND_MAX 9999 ???

Reply

Marsh Posté le 24-08-2004 à 22:47:23    

BlastRock a écrit :

Citation :

rand() renvoie un entier non-signé sur entre 0 et RAND_MAX


et comment on le change ce RAND_MAX ?
faut faire #undef RAND_MAX et #define RAND_MAX 9999 ???

dis t'en   as pas marre de poser 36 questions quand bien même on file tout cuit ?

Reply

Marsh Posté le 24-08-2004 à 22:47:28    

BlastRock a écrit :

Citation :

rand() renvoie un entier non-signé sur entre 0 et RAND_MAX


et comment on le change ce RAND_MAX ?
faut faire #undef RAND_MAX et #define RAND_MAX 9999 ???


[:rofl]


---------------
From now on, you will speak only when spoken to, and the first and last words out of your filthy sewers will be "Sir!"
Reply

Marsh Posté le 24-08-2004 à 22:47:28   

Reply

Marsh Posté le 24-08-2004 à 22:47:37    

et commen on fait "Taz a ecrit :" ?

Reply

Marsh Posté le 24-08-2004 à 22:48:17    

ta pas compris le truc, RAND_MAX t'indique juste la valeur max de l'entier non signé généré par rand

Reply

Marsh Posté le 24-08-2004 à 22:49:51    

ouarf j'en peux plus ouvre tes yeux bordel


---------------
From now on, you will speak only when spoken to, and the first and last words out of your filthy sewers will be "Sir!"
Reply

Marsh Posté le 24-08-2004 à 22:50:55    

BlastRock a écrit :

et commen on fait "Taz a ecrit :" ?

quoi que tu répondes, je rajoute un fraternel 'Ta gueule :o'

Reply

Marsh Posté le 24-08-2004 à 22:52:47    

j'ai compris, mais je veux changer RAND_MAX pour ne pas avoir un nombre trop grand

Reply

Marsh Posté le 24-08-2004 à 22:53:04    

mais non!


---------------
From now on, you will speak only when spoken to, and the first and last words out of your filthy sewers will be "Sir!"
Reply

Marsh Posté le 24-08-2004 à 22:53:56    

BlastRock a écrit :

j'ai compris, mais je veux changer RAND_MAX pour ne pas avoir un nombre trop grand

maintenant on passe au verbe 'pouvoir'

Reply

Marsh Posté le 24-08-2004 à 22:54:05    

BlastRock -> ta lu les liens  ?

Reply

Marsh Posté le 24-08-2004 à 22:56:26    

ouai

Reply

Marsh Posté le 24-08-2004 à 22:56:40    

on tient un bon boulet qui sait pas lire là :/


---------------
From now on, you will speak only when spoken to, and the first and last words out of your filthy sewers will be "Sir!"
Reply

Marsh Posté le 24-08-2004 à 22:57:28    

mais je sais lire...
je suis juste un piti débutant

Reply

Marsh Posté le 24-08-2004 à 22:58:11    


 
tes questions n'ont pas lieu d'etre si c'est le cas

Reply

Marsh Posté le 24-08-2004 à 22:58:23    

Je veux changer LLONG_MAX pour gérer des bignums, comment on fait ? :o

Reply

Marsh Posté le 24-08-2004 à 22:59:04    

BlastRock a écrit :

mais je sais lire...
je suis juste un piti débutant


 
bon ok alors tu prends la fonction de taz pré machée et tu l'utilises bordel :o :


unsigned my_better_rand(unsigned N)
{
  /**
   * beaucoup plus aléatoire et renvoie un entier entre 0 et N
   * (la je fais pas l'explication :oD )
   */
  return (unsigned)((double)rand()/((double)RAND_MAX+1)*N);
}


---------------
From now on, you will speak only when spoken to, and the first and last words out of your filthy sewers will be "Sir!"
Reply

Marsh Posté le 24-08-2004 à 23:02:09    

ah ! j'ai compris !!
dsl pour tout ce bordel...
j'y suis quand mm arrivé a la fin...  :)

Reply

Marsh Posté le 24-08-2004 à 23:02:41    

attends tu veux pas que te le compile pendant que j'y suis? :o


---------------
From now on, you will speak only when spoken to, and the first and last words out of your filthy sewers will be "Sir!"
Reply

Marsh Posté le 24-08-2004 à 23:03:04    

je viens de dire que c'est bon !

Reply

Marsh Posté le 24-08-2004 à 23:03:55    

ouais mais n'empeche ça a pas été facile avec toi :D


---------------
From now on, you will speak only when spoken to, and the first and last words out of your filthy sewers will be "Sir!"
Reply

Marsh Posté le 24-08-2004 à 23:04:30    

printf a écrit :

Je veux changer LLONG_MAX pour gérer des bignums, comment on fait ? :o


 
c'est trop ca :D

Reply

Marsh Posté le 24-08-2004 à 23:07:47    

100 contre un qu'il fait pas le srand et qu'on le revoit dans 3 jours ?

Reply

Marsh Posté le 24-08-2004 à 23:08:25    

nan on le revois avant parce qu'il arrivera pas à compiler :o


---------------
From now on, you will speak only when spoken to, and the first and last words out of your filthy sewers will be "Sir!"
Reply

Marsh Posté le 24-08-2004 à 23:08:37    

"on m'avais donné un lien mais ca marche pas :(" :D


Message édité par cris56 le 24-08-2004 à 23:09:33
Reply

Marsh Posté le 24-08-2004 à 23:12:53    

j'ai réussi a compiler !!!
je suis quand mm pas si nul que ca ! :kaola:

Reply

Marsh Posté le 24-08-2004 à 23:15:53    

et ca change à chaque execution ?

Reply

Marsh Posté le 24-08-2004 à 23:16:45    

ouai

Reply

Marsh Posté le 24-08-2004 à 23:17:19    

ok

Reply

Marsh Posté le 24-08-2004 à 23:18:32    

merci a tous !

Reply

Marsh Posté le    

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed