+Random Terrain Posted September 23, 2005 Share Posted September 23, 2005 I need to change my web site over to the new look and work on my version of the bB help page some more, but I need to try something with bB before I forget about it. For this thing I'm trying, I require a random number between 1 and 28. That's easy with other BASIC-type languages, but what is the best way with bB? Thanks. Quote Link to comment Share on other sites More sharing options...
+batari Posted September 23, 2005 Share Posted September 23, 2005 (edited) I need to change my web site over to the new look and work on my version of the bB help page some more, but I need to try something with bB before I forget about it. For this thing I'm trying, I require a random number between 1 and 28. That's easy with other BASIC-type languages, but what is the best way with bB? Thanks. 936890[/snapback] There are definitely other ways, but what comes to my mind is this. 10 a=rand:if a>215 then 10 a=a/8:a=a+1 Edited September 23, 2005 by batari Quote Link to comment Share on other sites More sharing options...
+batari Posted September 23, 2005 Share Posted September 23, 2005 Oops, I made a mistake - the above will give a number from 1 to 27. This should give you 1 to 28: 10 a=rand:if a>223 then 10 a=a/8:a=a+1 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted September 23, 2005 Author Share Posted September 23, 2005 (edited) Oops, I made a mistake - the above will give a number from 1 to 27. This should give you 1 to 28: 10 a=rand:if a>223 then 10 a=a/8:a=a+1 936947[/snapback] Thanks. Would that give me a problem if a was 0 because of the division? Whether or not it's a problem with bB, would this work OK? a=rand : if a<9 || a>223 then a=223 a=a/8 : a=a+1 Edited September 23, 2005 by Random Terrain Quote Link to comment Share on other sites More sharing options...
+batari Posted September 23, 2005 Share Posted September 23, 2005 Oops, I made a mistake - the above will give a number from 1 to 27. This should give you 1 to 28: 10 a=rand:if a>223 then 10 a=a/8:a=a+1 936947[/snapback] Thanks. Would that give me a problem if a was 0 because of the division? Whether or not it's a problem with bB, would this work OK? Doing 0/8 is not a problem. Doing something like 8/0 will generate an error in most languages, but not bB. It traps division by zero and just returns zero. a=rand : if a<9 || a>223 then a=223 a=a/8 : a=a+1 936970[/snapback] The above would produce a number from 2 to 28, and would strongly favor 28 (which would occur roughly 20% of the time, as opposed to around 3% for the other digits.) Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted September 23, 2005 Author Share Posted September 23, 2005 Doing 0/8 is not a problem. Doing something like 8/0 will generate an error in most languages, but not bB. It traps division by zero and just returns zero. That's great news. That sounds like something to add to the help file. Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted September 24, 2005 Share Posted September 24, 2005 I need to change my web site over to the new look and work on my version of the bB help page some more, but I need to try something with bB before I forget about it. For this thing I'm trying, I require a random number between 1 and 28. That's easy with other BASIC-type languages, but what is the best way with bB? Thanks. 936890[/snapback] Fred already gave you a way to do it, but here's another idea: a=rand reduce_a if a>28 then a=a-28:goto reduce_a Michael Rideout Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.