With the above code I can get only integer values. This is because I am using randi function which generates integer only. I would like to know is there any way of generating floating point numbers randomly?
Apart from above suggested methods, there are also various mathematical subroutines to generate random numbers i.e. Mid-Square method( what L.E. Jessen suggested), Congruence methods with largest prime modulo.(Ref. Book, Simulation: Seldon Ross).
Otherwise,
1. Generate between (0,1); say 'r' of length at least four.
2. random no. = (+/-)5*r
3. Discard integers if not required.
Generating random numbers in (0,1) by rand(), numbers will be uniform and independent. Further, there will be no auto correlation. The sequence of random numbers will be almost cycle free.
rand() represent random number between 0 to 32000 . If want to convert between -5 and +5 then first % by 100 which gives you number 0 to 99 then divide number by 10 which gives you number between 1 to 10. Next step is to add with -5 . finally gives you number between -5 to +g
/////////////////////////////////code in java language...//////////////////////////////////////////////////
public static void main()
{
int k=(Math.random()-5 +10); gives u number between -5 and +5
}
////////////////Both codes are executable try it///////////////////////////////////////////////////////
if you need more help in coading just post the messgae