- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i want to generate a real exponentially distributed random number, x,and divide this by another real number, t. If this result of this division gives me a real number with a decimal remainder, say 1.225, i want to convert this number to an integer. If i convert it directly will it simply discard the decimal part or will it round it to the nearest whole number? Also how would i go about doing this?
The basic idea is that t is a fixed interval wich will always be a whole number and i want to divide the random number generated into intervals of t. The conversion to an integer is to allow me to know which interval the number x falls in. So for instance if after the division i had a value of 6, then i know that the random number lies in the interval (6*t,7*t).
Any help or suggestions would be greatly recieved.
Cheers
The basic idea is that t is a fixed interval wich will always be a whole number and i want to divide the random number generated into intervals of t. The conversion to an integer is to allow me to know which interval the number x falls in. So for instance if after the division i had a value of 6, then i know that the random number lies in the interval (6*t,7*t).
Any help or suggestions would be greatly recieved.
Cheers
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
int(x / t) will truncate.
nint(x / t) will round to the nearest integer; if the fractional part is EXACTLY 0.5 then I think it rounds to nearest even integer.
You probably want the simple int() form.
nint(x / t) will round to the nearest integer; if the fractional part is EXACTLY 0.5 then I think it rounds to nearest even integer.
You probably want the simple int() form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - dudley@wrcplc.co.uk
int(x / t) will truncate.
nint(x / t) will round to the nearest integer; if the fractional part is EXACTLY 0.5 then I think it rounds to nearest even integer.
You probably want the simple int() form.
nint(x / t) will round to the nearest integer; if the fractional part is EXACTLY 0.5 then I think it rounds to nearest even integer.
You probably want the simple int() form.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page