Question about random()

Discuss programming in the QuakeC language.
Post Reply
Orion
Posts: 476
Joined: Fri Jan 12, 2007 6:32 pm
Location: Brazil

Question about random()

Post by Orion »

Does random() only return 10 different random numbers, between 0 and 1?
I've tested it with ftos() and it only gave me 0.1, 0.4, 0.7 etc...
I dunno if ftos() round things up a little, but can random() return something like 0.15? 0.00001, etc?
taniwha
Posts: 401
Joined: Thu Jan 14, 2010 7:11 am
Contact:

Re: Question about random()

Post by taniwha »

It's ftos. The original code used %5.1f for the format. Try multiplying the result by some scale (eg, 1000).
Leave others their otherness.
http://quakeforge.net/
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Question about random()

Post by Spike »

If using DP, you can use the sprintf builtin to view the number more fully. eg:
bprint(sprintf("random number is %f\n", random()));

This allows you to use your own precision etc.
Hint: try %g for a terse but accurate representation of a float.

Different engines can use different precision in ftos. Particuarly with nq vs qw.
Post Reply