Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1624 connectés 

  FORUM HardWare.fr
  Programmation
  C

  nombre aléatoire

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

nombre aléatoire

n°831252
blastrock
Posté le 24-08-2004 à 22:03:05  profilanswer
 

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:

mood
Publicité
Posté le 24-08-2004 à 22:03:05  profilanswer
 

n°831259
Evadream -​jbd-
Posté le 24-08-2004 à 22:08:43  profilanswer
 

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.

n°831266
blastrock
Posté le 24-08-2004 à 22:17:39  profilanswer
 

et ca corespond a quoi RAND_MAX ???

n°831268
Taz
bisounours-codeur
Posté le 24-08-2004 à 22:28:19  profilanswer
 

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

n°831274
blastrock
Posté le 24-08-2004 à 22:32:35  profilanswer
 

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
n°831282
Evadream -​jbd-
Posté le 24-08-2004 à 22:34:57  profilanswer
 

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 ;)

n°831294
Taz
bisounours-codeur
Posté le 24-08-2004 à 22:44:06  profilanswer
 

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

n°831298
blastrock
Posté le 24-08-2004 à 22:46:23  profilanswer
 

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 ???

n°831300
Taz
bisounours-codeur
Posté le 24-08-2004 à 22:47:23  profilanswer
 

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 ?

n°831301
schnapsman​n
Zaford Beeblefect
Posté le 24-08-2004 à 22:47:28  profilanswer
 

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!"
mood
Publicité
Posté le 24-08-2004 à 22:47:28  profilanswer
 

n°831303
blastrock
Posté le 24-08-2004 à 22:47:37  profilanswer
 

et commen on fait "Taz a ecrit :" ?

n°831305
cris56
Posté le 24-08-2004 à 22:48:17  profilanswer
 

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

n°831307
schnapsman​n
Zaford Beeblefect
Posté le 24-08-2004 à 22:49:51  profilanswer
 

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!"
n°831310
Taz
bisounours-codeur
Posté le 24-08-2004 à 22:50:55  profilanswer
 

BlastRock a écrit :

et commen on fait "Taz a ecrit :" ?

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

n°831313
blastrock
Posté le 24-08-2004 à 22:52:47  profilanswer
 

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

n°831314
schnapsman​n
Zaford Beeblefect
Posté le 24-08-2004 à 22:53:04  profilanswer
 

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!"
n°831317
Taz
bisounours-codeur
Posté le 24-08-2004 à 22:53:56  profilanswer
 

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'

n°831319
cris56
Posté le 24-08-2004 à 22:54:05  profilanswer
 

BlastRock -> ta lu les liens  ?

n°831326
blastrock
Posté le 24-08-2004 à 22:56:26  profilanswer
 

ouai

n°831327
schnapsman​n
Zaford Beeblefect
Posté le 24-08-2004 à 22:56:40  profilanswer
 

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!"
n°831331
blastrock
Posté le 24-08-2004 à 22:57:28  profilanswer
 

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

n°831334
cris56
Posté le 24-08-2004 à 22:58:11  profilanswer
 


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

n°831336
printf
Baston !
Posté le 24-08-2004 à 22:58:23  profilanswer
 

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

n°831340
schnapsman​n
Zaford Beeblefect
Posté le 24-08-2004 à 22:59:04  profilanswer
 

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!"
n°831351
blastrock
Posté le 24-08-2004 à 23:02:09  profilanswer
 

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

n°831352
schnapsman​n
Zaford Beeblefect
Posté le 24-08-2004 à 23:02:41  profilanswer
 

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!"
n°831353
blastrock
Posté le 24-08-2004 à 23:03:04  profilanswer
 

je viens de dire que c'est bon !

n°831356
schnapsman​n
Zaford Beeblefect
Posté le 24-08-2004 à 23:03:55  profilanswer
 

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!"
n°831358
cris56
Posté le 24-08-2004 à 23:04:30  profilanswer
 

printf a écrit :

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


 
c'est trop ca :D

n°831364
Taz
bisounours-codeur
Posté le 24-08-2004 à 23:07:47  profilanswer
 

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

n°831365
schnapsman​n
Zaford Beeblefect
Posté le 24-08-2004 à 23:08:25  profilanswer
 

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!"
n°831366
cris56
Posté le 24-08-2004 à 23:08:37  profilanswer
 

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


Message édité par cris56 le 24-08-2004 à 23:09:33
n°831370
blastrock
Posté le 24-08-2004 à 23:12:53  profilanswer
 

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

n°831377
cris56
Posté le 24-08-2004 à 23:15:53  profilanswer
 

et ca change à chaque execution ?

n°831379
blastrock
Posté le 24-08-2004 à 23:16:45  profilanswer
 

ouai

n°831381
cris56
Posté le 24-08-2004 à 23:17:19  profilanswer
 

ok

n°831385
blastrock
Posté le 24-08-2004 à 23:18:32  profilanswer
 

merci a tous !

mood
Publicité
Posté le   profilanswer
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C

  nombre aléatoire

 

Sujets relatifs
Tirage de nombre aléatoire.nombre aléatoire
Générer un nombre aléatoire...[C]Rendre un nombre aléatoire.
[C/C++] Générer un nombre aléatoire[ JS ] générer un nombre aléatoire et probleme de tableau ( var )
CALCUL UN NOMBRE ALEATOIRE[PHP] générer un nombre aléatoire...
[assembleur] comment genereer un nombre aleatoireNombre aléatoire...
Plus de sujets relatifs à : nombre aléatoire


Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)