# Search:

Type: Posts; User: flp1969

Page 1 of 20 1

1. ## Thread: How to generate a random number in the interval of -1 and 1?

by flp1969
Replies
17
Views
517

### Ahhh... of course, since we change the scale from...

Ahhh... of course, since we change the scale from 2⁰ to 2⁻¹! Nice catch.
2. ## Thread: error in function

by flp1969
Replies
3
Views
153

### Looks like you are trying to mimic the asprintf()...

Looks like you are trying to mimic the asprintf() GNU's function:

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

int asprintf ( char **p, char *fmt, ... )
{
int size;
3. ## Thread: How to tell gcc to compile for Windows ?

by flp1969
Replies
6
Views
163

### There are some predefined symbols for Windows:...

There are some predefined symbols for Windows: _WIN32 (this exists on mingw and VC++), __WINNT__
4. ## Thread: How to generate a random number in the interval of -1 and 1?

by flp1969
Replies
17
Views
517

### That's interesting, Malcom! I completely forgot...

That's interesting, Malcom! I completely forgot about linear interpolation!

#include <stdlib.h>
#include <float.h>

#define lerp(min_, max_, norm) \
( (min_)*(1.0 - (norm)) + (max_)*(norm)...
5. ## Thread: How to generate a random number in the interval of -1 and 1?

by flp1969
Replies
17
Views
517

### In time: You are correct about the duplicates....

In time: You are correct about the duplicates. There are none. My mistake.
6. ## Thread: How to generate a random number in the interval of -1 and 1?

by flp1969
Replies
17
Views
517

### That's a common mistake. The precision of a...

That's a common mistake. The precision of a floating point type is measured in bits, not decimal digits. In the case of a `double` type, using IEEE 754 format, if you have all the 53 bits set (the...
7. ## Thread: How to generate a random number in the interval of -1 and 1?

by flp1969
Replies
17
Views
517

### Hummm... sorry again, john.c... Taking another...

Hummm... sorry again, john.c... Taking another look, your approach use the range between -0.999999999068677425384521484375 and 0.999999999068677425384521484375, inclusive. Mine is wider, from...
8. ## Thread: How to generate a random number in the interval of -1 and 1?

by flp1969
Replies
17
Views
517

### Interesting the use of casting to unsigned int to...

Interesting the use of casting to unsigned int to avoid overflows. I have only 1 consideration:

RAND_MAX not necessarily is INT_MAX. It could be UINT_MAX. But, of course, rand() returns an int......
9. ## Thread: How to generate a random number in the interval of -1 and 1?

by flp1969
Replies
17
Views
517

### My soluction: Reducing precision by 1 ULP. ...

My soluction: Reducing precision by 1 ULP.

#include <stdlib.h>
#include <math.h>
#include <float.h>

// Transform rand() return value to [-1.0 e 1.0] range.
#define XFRM_RAND(x) ( 2.0 *...
10. ## Thread: How to generate a random number in the interval of -1 and 1?

by flp1969
Replies
17
Views
517

### INCLUDING these two is, of course, very easy....

INCLUDING these two is, of course, very easy. Excluding them is easy too, but there is a trick.

Of course, I'm waiting to see some code before showing it... :)
11. ## Thread: How to generate a random number in the interval of -1 and 1?

by flp1969
Replies
17
Views
517

### Do you know how to get a random value in an...

Do you know how to get a random value in an interval of 0 to 2?
And... are you sure you need to exclude -1 and 1?

by flp1969
Replies
10
Views
407

### I adivce against this affirmative. For example: ...

I adivce against this affirmative. For example:

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

#define N 10

int main ( void )
{

by flp1969
Replies
10
Views
407

### The rand() function is often implemented using a...

The rand() function is often implemented using a "pseudo random number generator" called "linear congruence generator" (LCG). Most (if not all) "pseudo random number generators" depends on an initial...

by flp1969
Replies
10
Views
407

### You need to specify an initial "random" seed...

You need to specify an initial "random" seed before using rand():

#include <stdio.h>
#include <stdlib.h>
#ifndef _WIN32
#include <unistd.h>
#include <fcntl.h>
#else
#include <time.h>

by flp1969
Replies
10
Views
407

### Linear congruential generator - Wikipedia...

Linear congruential generator - Wikipedia

by flp1969
Replies
17
Views
446

17. ## Thread: Came back to random numbers and got decent randomness

by flp1969
Replies
17
Views
446

### ISO 9899:1999 (and beyond): 7.19.7.10 § 2:...

ISO 9899:1999 (and beyond):

7.19.7.10 § 2: "The puts function writes the string pointed to by s to the stream pointed to by stdout, and appends a new-line character to the output. The terminating...
18. ## Thread: Came back to random numbers and got decent randomness

by flp1969
Replies
17
Views
446

### I don't... puts() aumatically puts a '\n' the end...

I don't... puts() aumatically puts a '\n' the end of the string when printing...
19. ## Thread: Came back to random numbers and got decent randomness

by flp1969
Replies
17
Views
446

### You are using P6 instead of P3... P6 is for...

You are using P6 instead of P3... P6 is for BINARY RGB values, P3 is for textual numeric values.
20. ## Thread: Came back to random numbers and got decent randomness

by flp1969
Replies
17
Views
446

### Not random. Can't you see the pattern? ...

Not random. Can't you see the pattern?

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

#define bitsof(x) (sizeof(x)*CHAR_BIT)

static unsigned int val2rgb( unsigned int x )
{

by flp1969
Replies
11
Views
502

### Only if one of the pointers is NULL. Or, putting...

Only if one of the pointers is NULL. Or, putting the other way: If any of the fopen() fails.

by flp1969
Replies
11
Views
502

### Consider the case where file1 != NULL, file2 ==...

Consider the case where file1 != NULL, file2 == NULL and file3 != NULL (failed to open file2 only)...

if ( file1 == NULL && file2 == NULL && file3 == NULL )
Will evaluate to:

if ( 0 && 1 && 0...

by flp1969
Replies
11
Views
502

### You are assuming: 1- Struct members...

You are assuming:

1- Struct members alignment/padding will be the same for any architecture (false);
2- All architetures use the same endianmess (false);
3- All architectures use IEEE 754 format...
24. ## Thread: improve this cpp code?

by flp1969
Replies
10
Views
930

### Indentation is a good start

Indentation is a good start
25. ## Thread: modify char array in function || reading lines from file

by flp1969
Replies
7
Views
412

### One question: Since the lines (except the header)...

One question: Since the lines (except the header) are fixed as
<int> <int> <int> <string>
Where string has no spaces, Why not read a line and use sscanf() to get these values?

char...
Results 1 to 25 of 500
Page 1 of 20 1