Announcement

Collapse
No announcement yet.

FRESH MEAT sucht HILFE in RANDOMIZE

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • FRESH MEAT sucht HILFE in RANDOMIZE

    Hallo Hallo,

    ich benötige unbedingt Hilfe in Randomize, bitte !

    ich habe einige Hilfe im Forum mal ausprobiert,
    aber mein Visual C++ meckert mich trotzdem noch an.

    ich wollte nur ein Randomize mit Anfang und Maximal Grenze ausprobieren.

    Bitte schreib mir was ich alles berücksichtigen
    muss z.B. include und andere Sachen

    DANKE im VORRAUS

  • #2
    Hallo!

    Anbei ein kleines Beispielprogramm. Damit bekommst Du Pseudozufallszahlen im Bereich von 0 bis RAND_MAX. Für einen anderen Bereich ist eine kleine Umrechnung nötig:

    <PRE>
    Min+((double) rand())/RAND_MAX*(Max-Min)
    </PRE>

    Damit liegen die Zahlen dann im Bereich von Min bis Max.

    Ich hoffe ich konnte helfen?

    Viele Grüße<BR>
    Thomas

    <PRE>
    /* RAND.C: This program seeds the random-number generator
    * with the time, then displays 10 random integers.
    */

    #include <stdlib.h>
    #include <stdio.h>
    #include <time.h>

    void main( void )
    {
    int i;

    /* Seed the random-number generator with current time so that
    * the numbers will be different every time we run.
    */
    srand( (unsigned)time( NULL ) );

    /* Display 10 numbers. */
    for( i = 0; i < 10;i++ )
    printf( " %6d\n", rand() );
    }

    </PRE&gt

    Comment


    • #3
      Hi<BR>
      Folgendes habe ich mir selbst zusammengestrickt. Basis ist der von mir unten empfohlene RANMAR Zufallsgenerator.
      Sieht kompliziert und unglücklich Programmiert aus - ist aber ein WIRKLICH FANTASTISCHER Zufalls-Generator!!!!<BR><BR>

      //In stdafx.h<BR>
      #include <afxtempl.h><BR>

      //In DEINE ???.h<BR>
      BOOL bTest;<BR>
      int i97, j97;<BR>
      float u[98], c, cd, cm;<BR>
      float ranmar();<BR>
      void rmarin(int ij, int kl);<BR>
      int Rnd(int intMax, BOOL NegFlag);<BR>
      <BR>
      //In DEINE ????.cpp<BR>

      int C????Wnd::Rnd(int intMax, BOOL NegativFlag)<BR>
      {<BR>
      double xZahl = ranmar();<BR>
      if(NegativFlag)<BR>
      return ((double)xZahl - (int)xZahl) * intMax;<BR>
      else<BR>
      return abs((((double)xZahl - (int)xZahl) * intMax));<BR>
      }<BR>

      void C????Wnd::rmarin(int ij, int kl)<BR>
      {<BR>
      /*
      C This is the initialization routine for the random number generator RANMAR()
      C NOTE: The seed variables can have values between: 0 <= IJ <= 31328
      C 0 <= KL <= 30081
      C The random number sequences created by these two seeds are of sufficient
      C length to complete an entire calculation with. For example, if sveral
      C different groups are working on different parts of the same calculation,
      C each group could be assigned its own IJ seed. This would leave each group
      C with 30000 choices for the second seed. That is to say, this random
      C number generator can create 900 million different subsequences -- with
      C each subsequence having a length of approximately 10^30.
      C
      C Use IJ = 1802 & KL = 9373 to test the random number generator. The
      C subroutine RANMAR should be used to generate 20000 random numbers.
      C Then display the next six random numbers generated multiplied by 4096*4096
      C If the random number generator is working properly, the random numbers
      C should be:
      C 6533892.0 14220222.0 7275067.0
      C 6172232.0 8354498.0 10633180.0
      */<BR>
      int i, j, k, l, ii, jj, m;<BR>
      float s, t;<BR>

      ij %= 31328;<BR>
      kl %= 30081;<BR>

      i = (ij/177)%177 + 2;<BR>
      j = ij%177 + 2;<BR>
      k = (kl/169)%178 + 1;<BR>
      l = kl%169;<BR>

      for (ii=1; ii<=97; ii++)<BR> {<BR>
      s = (float)0.0;<BR>
      t = (float)0.5;<BR>
      for (jj=1; jj<=24; jj++)<BR> {<BR>
      m = (((i*j)%179)*k) % 179;<BR>
      i = j;<BR>
      j = k;<BR>
      k = m;<BR>
      l = (53*l + 1) % 169;<BR>
      if ((l*m)%64 >= 32) s += t;<BR>
      t *= (float)0.5;<BR>
      <BR>}
      u[ii] = s;<BR>
      }<BR>

      c = (float)362436.0 / (float)16777216.0;<BR>
      cd = (float)7654321.0 / (float)16777216.0;<BR>
      cm = (float)16777213.0 / (float)16777216.0;<BR>

      i97 = 97;<BR>
      j97 = 33;<BR>

      bTest = TRUE;<BR>
      <BR>}<BR>

      float C????Wnd::ranmar()<BR>
      {<BR>
      float uni;<BR>

      // auto-seed:<BR>
      if (bTest==FALSE)<BR>
      {<BR>
      rmarin(rand() % 31328, time( NULL ) % 30081);<BR>
      }<BR>

      uni = u[i97] - u[j97];<BR>
      if (uni < 0.0) uni += (float)1.0;<BR>
      u[i97] = uni;<BR>
      i97--;<BR>
      if (i97==0) i97 = 97;<BR>
      j97--;<BR>
      if (j97==0) j97 = 97;<BR>
      c -= cd;<BR>
      if (c<0.0) c += cm;<BR>
      uni -= c;<BR>
      if (uni<0.0) uni += (float)1.0;<BR>
      return uni;<BR>
      }<BR>

      Aufruf:<BR>
      BOOL NFlag = FALSE; //TRUE = Zuf.Negative Zahlen<BR>
      int max = 1000;<BR>
      int Zufall = Rnd(max, NFlag);<BR&gt

      Comment

      Working...
      X