about random() in BP7 
Author Message
 about random() in BP7

Hello

I want to have the randomized numbers in Borland C as in Borland Pascal,
how can I generate it in BC?

Roger



Wed, 18 Jun 1902 08:00:00 GMT  
 about random() in BP7

Quote:

>Hello

>I want to have the randomized numbers in Borland C as in Borland Pascal,
>how can I generate it in BC?

>Roger

I think what you're looking for is the srand() function in
STDLIB.H
It has an example in the help of BC (3.1, at least)
Hope this helps.

--

Return address is messed to deter spam.
Before replying, take out _REMOVE_



Wed, 18 Jun 1902 08:00:00 GMT  
 about random() in BP7

Quote:
>> I want to have the same randomized numbers in Borland C as in Borland
Pascal,
>> how can I generate it in BC?
>From your question, it sounds like you have Borland Pascal.  If so, just
look
>at the RTL, or use the de{*filter*}.  If not, send me e-mail and I'll provide
>more detail (must leave for appointment right now).

Yes, I have BP7 and BC 3.1/4.5
so can you provide me more details? (where is your emaill address?)
thanks for your help.

I set a special random seed, and I can generate the random numbers I want.
then I used the random() in Borland Pascal to encrypt some data,
and I can use the random() in Borland Pascal to decrypt it.
but I can't use the random() in BC to decrypt it.
that's why I want to get the same random() in BC.

Roger



Wed, 18 Jun 1902 08:00:00 GMT  
 about random() in BP7


Quote:
> >> I want to have the same randomized numbers in Borland C as in Borland
> Pascal,
> >> how can I generate it in BC?
> >From your question, it sounds like you have Borland Pascal.  If so, just
> look
> >at the RTL, or use the de{*filter*}.  If not, send me e-mail and I'll provide
> >more detail (must leave for appointment right now).

> Yes, I have BP7 and BC 3.1/4.5
> so can you provide me more details? (where is your emaill address?)
> thanks for your help.

> I set a special random seed, and I can generate the random numbers I want.
> then I used the random() in Borland Pascal to encrypt some data,
> and I can use the random() in Borland Pascal to decrypt it.
> but I can't use the random() in BC to decrypt it.
> that's why I want to get the same random() in BC.

Please note that TP up to 6.0 and TP/BP 7.0 are using incompatible
versions of random(),

Here is a C translation (tested) of both versions. (assuming 16 bit
unsigned and 32 bit unsigned long).

Quote:
>----------------------------------------------<

static unsigned long RandSeed = 0;

static unsigned long NewRandom(void)
{
  return RandSeed = RandSeed * 0x08088405UL + 1;

Quote:
}

unsigned random_TP60 (unsigned n)
/* function random(w:word):word;  TP <= 6.0 */
{
   return (unsigned)(NewRandom()>>16)%n;

Quote:
}

unsigned random_TP70 (unsigned n)
/* function random(w:word):word;  TP/BP 7.0 */
{
   unsigned long r = NewRandom();

   return (unsigned)
          ((((n*(r&0xffff))>>16)+n*(r>>16))>>16);

Quote:
}
>----------------------------------------------<

Regards
Horst


Wed, 18 Jun 1902 08:00:00 GMT  
 about random() in BP7

Quote:
> I want to have the randomized numbers in Borland C as in Borland Pascal,

Translate the formula
   seed:=a*seed+1
 with
   a =$0808 8405 =134 775 813
 in 32 bit to C.


Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. BP7 questions about random filenames and text input

2. BP7 questions about random filenames and text input

3. BP7 questions about random filenames and text input

4. BP7 questions about random filenames and text input

5. Random isn't random?

6. Random where no random should be!

7. Random isn't random?

8. Which known BP7 bugs did BP7.01 fix ?

9. random numbers

10. random seeds

11. help on RANDOM and converting int's to strings

12. Selecting a random record from a table

 

 
Powered by phpBB® Forum Software