Please tell me how to declare a String variable to be used to append 8 unique random numbers?

2009-08-28 8:42 am

回答 (3)

2009-08-28 9:12 am
✔ 最佳答案
Do you mean you have a string and want to add 8 characters TO the existing string?Or, do you have an array and want to add elements to the array, each with a set of 8 random numbers? Let's go for appending 8 random number characters as that is easier to run through than the array...

s$=""

a$="0123456789"

randomize 'initialize the random number generator

x = 0

for y=1 to 8

x=random(len(a$)) 'select a random number from 0 to length of a$

a$=s$=s$+substr(a$,x,1) ' append the number character

next y

print s$ ' print the 8 character number string

-=+=-

Is this the kind of thing you wish to do? Note that in this example, single digits CAN repeat within the string.
2016-05-28 6:50 pm
Two ways to define string in c language. 1) character array char name[20]; 2) pointer of character char name*;
2009-08-28 8:54 am
you should specify the programming language u r using c++, Java, so on


收錄日期: 2021-05-01 01:03:49
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20090828004219AA42Pc3

檢視 Wayback Machine 備份